Search in sources :

Example 21 with LinkAttributes

use of org.eclipse.mylyn.wikitext.parser.LinkAttributes in project mylyn.docs by eclipse.

the class HtmlDocumentBuilder method applyLinkAttributes.

private void applyLinkAttributes(Attributes attributes, String href) {
    applyAttributes(attributes);
    boolean hasTarget = false;
    String rel = linkRel;
    if (attributes instanceof LinkAttributes) {
        LinkAttributes linkAttributes = (LinkAttributes) attributes;
        if (linkAttributes.getTarget() != null) {
            hasTarget = true;
            // $NON-NLS-1$
            writer.writeAttribute("target", linkAttributes.getTarget());
        }
        if (linkAttributes.getRel() != null) {
            rel = rel == null ? linkAttributes.getRel() : linkAttributes.getRel() + ' ' + rel;
        }
    }
    if (attributes.getTitle() != null && attributes.getTitle().length() > 0) {
        // $NON-NLS-1$
        writer.writeAttribute("title", attributes.getTitle());
    }
    if (!hasTarget && defaultAbsoluteLinkTarget != null && href != null) {
        if (isExternalLink(href)) {
            // $NON-NLS-1$
            writer.writeAttribute("target", defaultAbsoluteLinkTarget);
        }
    }
    if (rel != null) {
        // $NON-NLS-1$
        writer.writeAttribute("rel", rel);
    }
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes)

Example 22 with LinkAttributes

use of org.eclipse.mylyn.wikitext.parser.LinkAttributes in project mylyn.docs by eclipse.

the class SplittingHtmlDocumentBuilder method emitNavigation.

private void emitNavigation(boolean header) {
    String currentName = currentFile.getName();
    List<SplitOutlineItem> pageOrder = outline.getPageOrder();
    SplitOutlineItem previous = null;
    SplitOutlineItem next = null;
    SplitOutlineItem current = null;
    boolean foundPage = false;
    for (SplitOutlineItem page : pageOrder) {
        if (page.getSplitTarget().equals(currentName)) {
            foundPage = true;
            current = page;
        } else if (!foundPage) {
            previous = page;
        } else {
            next = page;
            break;
        }
    }
    boolean rootPage = rootFile.getName().equals(currentFile.getName());
    if (next == null && previous == null && rootPage) {
        return;
    }
    if (!header) {
        // $NON-NLS-1$
        out.charactersUnescaped("<hr class=\"navigation-separator\"/>");
    }
    TableAttributes tableAttributes = new TableAttributes();
    // $NON-NLS-1$
    tableAttributes.setCssClass("navigation");
    // $NON-NLS-1$
    tableAttributes.setCssStyle("width: 100%;");
    // $NON-NLS-1$
    tableAttributes.setBorder("0");
    // $NON-NLS-1$
    tableAttributes.setSummary("navigation");
    out.beginBlock(BlockType.TABLE, tableAttributes);
    TableCellAttributes tableCellAttributes;
    if (header) {
        // header row, emit title of page
        out.beginBlock(BlockType.TABLE_ROW, new Attributes());
        tableCellAttributes = new TableCellAttributes();
        // $NON-NLS-1$
        tableCellAttributes.setAlign("center");
        // $NON-NLS-1$
        tableCellAttributes.setCssStyle("width: 100%");
        // $NON-NLS-1$
        tableCellAttributes.setColspan("3");
        out.beginBlock(BlockType.TABLE_CELL_HEADER, tableCellAttributes);
        if (rootPage) {
            out.characters(rootBuilder.getTitle());
        } else {
            // $NON-NLS-1$
            out.characters(current == null ? "" : current.getLabel());
        }
        out.endBlock();
        out.endBlock();
    }
    // navigation row
    out.beginBlock(BlockType.TABLE_ROW, new Attributes());
    LinkAttributes linkAttributes;
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("left");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 20%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (previous != null) {
        linkAttributes = new LinkAttributes();
        linkAttributes.setTitle(previous.getLabel());
        if (navigationImages) {
            ImageAttributes imageAttributes = new ImageAttributes();
            // $NON-NLS-1$
            imageAttributes.setAlt(Messages.getString("SplittingHtmlDocumentBuilder.Previous"));
            out.imageLink(linkAttributes, imageAttributes, previous.getSplitTarget(), // $NON-NLS-1$
            computeNavImagePath(Messages.getString("SplittingHtmlDocumentBuilder.Previous_Image")));
        } else {
            out.link(linkAttributes, previous.getSplitTarget(), // $NON-NLS-1$
            Messages.getString("SplittingHtmlDocumentBuilder.Previous"));
        }
    }
    out.endBlock();
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("center");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 60%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (!header && !rootPage) {
        linkAttributes = new LinkAttributes();
        linkAttributes.setTitle(rootBuilder.getTitle());
        if (navigationImages) {
            ImageAttributes imageAttributes = new ImageAttributes();
            imageAttributes.setAlt(rootBuilder.getTitle());
            out.imageLink(linkAttributes, imageAttributes, rootFile.getName(), // $NON-NLS-1$
            computeNavImagePath(Messages.getString("SplittingHtmlDocumentBuilder.Home_Image")));
        } else {
            // $NON-NLS-1$
            out.link(linkAttributes, rootFile.getName(), Messages.getString("SplittingHtmlDocumentBuilder.Home"));
        }
    }
    out.endBlock();
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("right");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 20%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (next != null) {
        linkAttributes = new LinkAttributes();
        linkAttributes.setTitle(next.getLabel());
        if (navigationImages) {
            ImageAttributes imageAttributes = new ImageAttributes();
            // $NON-NLS-1$
            imageAttributes.setAlt(Messages.getString("SplittingHtmlDocumentBuilder.Next"));
            out.imageLink(linkAttributes, imageAttributes, next.getSplitTarget(), // $NON-NLS-1$
            computeNavImagePath(Messages.getString("SplittingHtmlDocumentBuilder.Next_Image")));
        } else {
            out.link(linkAttributes, next.getSplitTarget(), // $NON-NLS-1$
            Messages.getString("SplittingHtmlDocumentBuilder.Next"));
        }
    }
    out.endBlock();
    // navigation row
    out.endBlock();
    // navigation title row
    out.beginBlock(BlockType.TABLE_ROW, new Attributes());
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("left");
    // $NON-NLS-1$
    tableCellAttributes.setValign("top");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 20%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (previous != null) {
        out.characters(previous.getLabel());
    }
    out.endBlock();
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("center");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 60%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    out.endBlock();
    tableCellAttributes = new TableCellAttributes();
    // $NON-NLS-1$
    tableCellAttributes.setAlign("right");
    // $NON-NLS-1$
    tableCellAttributes.setValign("top");
    // $NON-NLS-1$
    tableCellAttributes.setCssStyle("width: 20%");
    out.beginBlock(BlockType.TABLE_CELL_NORMAL, tableCellAttributes);
    if (next != null) {
        out.characters(next.getLabel());
    }
    out.endBlock();
    // navigation title row
    out.endBlock();
    // table
    out.endBlock();
    if (header) {
        // $NON-NLS-1$
        out.charactersUnescaped("<hr class=\"navigation-separator\"/>");
    }
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Attributes(org.eclipse.mylyn.wikitext.parser.Attributes) TableCellAttributes(org.eclipse.mylyn.wikitext.parser.TableCellAttributes) TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes) TableAttributes(org.eclipse.mylyn.wikitext.parser.TableAttributes) ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) TableCellAttributes(org.eclipse.mylyn.wikitext.parser.TableCellAttributes)

Example 23 with LinkAttributes

use of org.eclipse.mylyn.wikitext.parser.LinkAttributes in project statecharts by Yakindu.

the class HubspotDocumentBuilder method beginSpan.

@Override
public void beginSpan(final SpanType type, final Attributes attributes) {
    if (isEarlySeparator) {
        if (!isProcessingHeading)
            h2.beginSpan(type, attributes);
    } else {
        if (SpanType.LINK == type && attributes instanceof LinkAttributes) {
            final LinkAttributes linkAttributes = (LinkAttributes) attributes;
            final String hrefOrHashName = linkAttributes.getHref();
            if (hrefOrHashName.startsWith("http")) {
                /*
					 * An external link should be opened in a new tab or window
					 * and thus gets the target="_blank" attribute attached.
					 */
                linkAttributes.setTarget("_blank");
            } else if (hrefOrHashName.startsWith("../")) {
                /*
					 * Links pointing into the parent directory are referring
					 * another section of our documentation are require some
					 * special handling in order to comply with the Hubspot
					 * template.
					 */
                boolean hasHash = false;
                boolean hasFragment = false;
                boolean hasFilename = false;
                final String fragmentID;
                // Get the fragment ID:
                int fragmentPosition = hrefOrHashName.lastIndexOf('#');
                if (fragmentPosition >= 0) {
                    hasHash = true;
                    if (fragmentPosition + 1 < hrefOrHashName.length())
                        hasFragment = true;
                    fragmentPosition++;
                } else
                    fragmentPosition = hrefOrHashName.length();
                fragmentID = hrefOrHashName.substring(fragmentPosition);
                // Strip the last component (filename) from the URL, if any:
                final StringBuilder b = new StringBuilder();
                int filenamePosition = hrefOrHashName.lastIndexOf('/', fragmentPosition - 1);
                hasFilename = filenamePosition >= 2 && filenamePosition + 2 <= fragmentPosition;
                if (hasFilename)
                    b.append(hrefOrHashName.substring(0, filenamePosition));
                else
                    b.append(hrefOrHashName.substring(0, fragmentPosition - (hasHash ? 1 : 0)));
                if (hasFilename)
                    b.append('/');
                if (hasFragment) {
                    // Find the fragment's H1 heading:
                    final Heading h1Heading = lookupH1HeadingOf(pass1Headings, fragmentID);
                    // Append H1 heading's ID to the URL:
                    if (h1Heading != null)
                        b.append(h1Heading.getId());
                    else
                        System.err.println("WARNING: H1 heading for fragment #" + fragmentID + " not found.");
                    // Append fragment ID.
                    b.append('#');
                    b.append(fragmentID);
                } else if (hasHash)
                    b.append('#');
                linkAttributes.setHref(b.toString());
            }
        }
        super.beginSpan(type, attributes);
    }
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes)

Example 24 with LinkAttributes

use of org.eclipse.mylyn.wikitext.parser.LinkAttributes in project mylyn.docs by eclipse.

the class AsciiDocDocumentBuilderTest method testImageLinkWithLinkAttributes.

@Test
public void testImageLinkWithLinkAttributes() {
    builder.beginDocument();
    LinkAttributes linkAttr = new LinkAttributes();
    linkAttr.setTitle("Optional link title");
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.setAlt("Alt text");
    imageAttr.setTitle("Optional image title");
    builder.imageLink(linkAttr, imageAttr, "http://example.net/", "/path/to/img.jpg");
    builder.endDocument();
    assertMarkup("link:http://example.net/[image:/path/to/img.jpg[Alt text, title=\"Optional image title\"]]\n\n");
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) ImageAttributes(org.eclipse.mylyn.wikitext.parser.ImageAttributes) Test(org.junit.Test)

Example 25 with LinkAttributes

use of org.eclipse.mylyn.wikitext.parser.LinkAttributes in project mylyn.docs by eclipse.

the class AsciiDocDocumentBuilderTest method testLinkWithTitle.

@Test
public void testLinkWithTitle() {
    // The title properties is ignored.
    builder.beginDocument();
    builder.characters("This is ");
    LinkAttributes attr = new LinkAttributes();
    attr.setTitle("Title");
    builder.link(attr, "http://example.com/", "an example");
    builder.characters(" inline link.");
    builder.endDocument();
    assertMarkup("This is link:http://example.com/[an example] inline link.\n\n");
}
Also used : LinkAttributes(org.eclipse.mylyn.wikitext.parser.LinkAttributes) Test(org.junit.Test)

Aggregations

LinkAttributes (org.eclipse.mylyn.wikitext.parser.LinkAttributes)45 Test (org.junit.Test)16 ImageAttributes (org.eclipse.mylyn.wikitext.parser.ImageAttributes)12 Attributes (org.eclipse.mylyn.wikitext.parser.Attributes)10 ImageLinkEvent (org.eclipse.mylyn.wikitext.parser.builder.event.ImageLinkEvent)5 TableAttributes (org.eclipse.mylyn.wikitext.parser.TableAttributes)2 LinkEvent (org.eclipse.mylyn.wikitext.parser.builder.event.LinkEvent)2 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 IContainer (org.eclipse.core.resources.IContainer)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 Region (org.eclipse.jface.text.Region)1 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1 ListAttributes (org.eclipse.mylyn.wikitext.parser.ListAttributes)1 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)1