@Override public int processLineContent(String line, int offset) { if (blockLineCount == 0) { Attributes attributes = new Attributes(); // 0-offset matches may start with the "hn. " prefix. level = Integer.parseInt(matcher.group(1)); offset = matcher.start(2); if (attributes.getId() == null) { attributes.setId(state.getIdGenerator().newId("h" + level, line.substring(offset))); //$NON-NLS-1$ } builder.beginHeading(level, attributes); } if (blockLineCount != 0 || markupLanguage.isEmptyLine(line)) { setClosed(true); return 0; } ++blockLineCount; getMarkupLanguage().emitMarkupLine(getParser(), state, line, offset); return -1; }
@Override public boolean canStart(String line, int lineOffset) { if (lineOffset == 0 && !markupLanguage.isFilterGenerativeContents()) { matcher = startPattern.matcher(line); return matcher.matches(); } else { matcher = null; return false; } } }
public void setMarkupLanguage(MarkupLanguage markupLanguage) { if (markupLanguage == this.markupLanguage || (markupLanguage != null && this.markupLanguage != null && markupLanguage.getName().equals( this.markupLanguage.getName()))) { return; } this.markupLanguage = markupLanguage; delegate = markupLanguage == null ? null : WikiText.getMarkupValidator(markupLanguage.getName()); }
public boolean isNestingEnabled() { if (getMarkupLanguage().blockWantsControl() != null && !getMarkupLanguage().blockWantsControl().equals("list")) { // Disable nesting, if another block type is trying to regain control return false; } else { // Enable nesting, but not if this is outline parsing (i.e. for {toc}) return !getMarkupLanguage().isFilterGenerativeContents(); } }
public Block startBlock(String line, int lineOffset) { if (isEmptyLine(line)) { // nothing starts on an empty line return null; } for (Block block : getBlocks()) { if (block.canStart(line, lineOffset)) { Block clone = block.clone(); if (clone == null) { // Special case for TableBlock: // Must not be cloned because 'canStart' needs // to be aware of the table state. return block; } return clone; } } return null; }
public OutlineItem parse(OutlineItem root, String markup) { if (markup == null || markup.length() == 0 || markupLanguage == null) { root.setLength(markup == null ? 0 : markup.length()); return root; } root.setLength(markup.length()); markupLanguage.setFilterGenerativeContents(true); markupLanguage.setBlocksOnly(isBlocksOnly()); try { OutlineBuilder outlineBuilder = (OutlineBuilder) createOutlineUpdater(root); outlineBuilder.idGenerator.setGenerationStrategy(markupLanguage.getIdGenerationStrategy()); MarkupParser markupParser = new MarkupParser(); markupParser.setBuilder(outlineBuilder); markupParser.setMarkupLanguage(markupLanguage); markupParser.parse(markup); } finally { markupLanguage.setFilterGenerativeContents(false); markupLanguage.setBlocksOnly(false); } return root; }
@Override public void emit() { Attributes attributes = new Attributes(); getBuilder().beginSpan(spanType, attributes); if (nesting) { getMarkupLanguage().emitMarkupLine(parser, state, getStart(this), getContent(this), 0); } else { getMarkupLanguage().emitMarkupText(parser, state, getContent(this)); } getBuilder().endSpan(); } }
/** * Emit a markup line that may contain phrase modifiers and replacement tokens, but no block modifiers. * * @param parser * @param state * @param line * @param offset */ public void emitMarkupLine(MarkupParser parser, ContentState state, String line, int offset) { emitMarkupLine(parser, state, 0, line, offset); }
@Override public int processLineContent(String line, int offset) { if (blockLineCount == 0) { Attributes attributes = new Attributes(); if (offset == 0) { // 0-offset matches may start with the "hn. " prefix. level = Integer.parseInt(matcher.group(1)); Textile.configureAttributes(attributes, matcher, 2, true); offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET); } if (attributes.getId() == null) { attributes.setId(state.getIdGenerator().newId("h" + level, line.substring(offset))); //$NON-NLS-1$ } builder.beginHeading(level, attributes); } if (markupLanguage.isEmptyLine(line)) { setClosed(true); return 0; } if (blockLineCount != 0) { getMarkupLanguage().emitMarkupText(getParser(), state, "\n"); //$NON-NLS-1$ } ++blockLineCount; getMarkupLanguage().emitMarkupLine(getParser(), state, line, offset); return -1; }
@Override public int processLineContent(String line, int offset) { if (blockLineCount == 0) { Attributes attributes = new Attributes(); Textile.configureAttributes(attributes, matcher, 1, true); offset = matcher.start(LINE_REMAINDER_GROUP_OFFSET); extended = matcher.group(EXTENDED_GROUP) != null; builder.beginBlock(BlockType.PREFORMATTED, attributes); } if (markupLanguage.isEmptyLine(line) && !extended) { setClosed(true); return 0; } else if (extended && Textile.explicitBlockBegins(line, offset)) { setClosed(true); return offset; } ++blockLineCount; final String lineText = offset > 0 ? line.substring(offset) : line; if (blockLineCount > 1 || lineText.trim().length() > 0) { builder.characters(lineText); builder.characters("\n"); //$NON-NLS-1$ } return -1; }
public void processContent(MarkupParser parser, String markupContent, boolean asDocument) { initializeSyntax(false); initProcessors(); ContentState state = createState(); state.setMarkupContent(markupContent); LocationTrackingReader reader = new LocationTrackingReader(new StringReader(markupContent)); currentBlock = startBlock(line, lineOffset); if (currentBlock == null) { emitMarkupLine(parser, state, line, lineOffset); break;
emitMarkupText(parser, state, line.substring(offset)); return; state.setShift(previousShift + textLineOffset); for (;;) { PatternBasedElementProcessor phraseModifier = getPhraseModifierSyntax().findPatternBasedElement(line, offset); if (phraseModifier != null) { state.setLineSegmentEndOffset(state.getShift() + newOffset); String text = line.substring(offset, newOffset); emitMarkupText(parser, state, text); state.setLineCharacterOffset(state.getShift() + offset); state.setLineSegmentEndOffset(state.getShift() + line.length()); emitMarkupText(parser, state, line.substring(offset)); break;
PatternBasedElementProcessor tokenReplacement = getReplacementTokenSyntax().findPatternBasedElement(text, offset); if (tokenReplacement != null) { if (offset < newOffset) { String text2 = text.substring(offset, newOffset); emitMarkupText(parser, state, text2);
markupLanguage.setBlocksOnly(partitionOffset != -1); markupLanguage.setFilterGenerativeContents(true); PartitionBuilder partitionBuilder = new PartitionBuilder(startOffset, markupLanguage.isBlocksOnly()); markupParser.setBuilder(partitionBuilder); markupLanguage.getName() }); if (FastMarkupPartitioner.debug) { String markupSavePath = saveToTempFile(markupLanguage, markupContent);
markupLanguage = markupLanguage.clone(); markupLanguage.setEnableMacros(true); markupLanguage.setBlocksOnly(false); markupLanguage.setFilterGenerativeContents(false);
private void configurePartitioning(IDocument document) { FastMarkupPartitioner partitioner = new FastMarkupPartitioner(); partitioner.setMarkupLanguage(markupLanguage.clone()); partitioner.connect(document); document.setDocumentPartitioner(partitioner); }
public void reparse(IDocument document, Block block) { MarkupParser markupParser = new MarkupParser(markupLanguage); markupLanguage.setBlocksOnly(false); markupLanguage.setFilterGenerativeContents(true); PartitionBuilder partitionBuilder = new PartitionBuilder(block.getOffset(), false); markupParser.setBuilder(partitionBuilder); try { markupParser.parse(document.get(block.getOffset(), block.getLength())); for (Segment<?> s : partitionBuilder.outerBlock.getChildren().asList()) { if (s.getOffset() == block.getOffset()) { if (s instanceof Block) { block.replaceChildren(s); block.setSpansComputed(true); break; } } } } catch (BadLocationException e) { throw new IllegalStateException(e); } }
private String computeCheatSheet(MarkupLanguage markupLanguage) { HelpContent content = null; if (markupLanguage != null) { content = WikiTextUiPlugin.getDefault().getCheatSheets().get(markupLanguage.getName()); if (content == null) { // explore the hierarchy for cheat-sheet content MarkupLanguage l = markupLanguage; while (content == null && l != null && l.getExtendsLanguage() != null) { l = WikiText.getMarkupLanguage(l.getExtendsLanguage()); if (l != null) { content = WikiTextUiPlugin.getDefault().getCheatSheets().get(l.getName()); } } } } if (content != null) { try { return content.getContent(); } catch (Exception e) { WikiTextUiPlugin.getDefault().log(e); } } return NLS.bind(Messages.ShowCheatSheetCommand_noCheatSheetContent, new Object[] { markupLanguage == null ? Messages.ShowCheatSheetCommand_unknownLanguage : markupLanguage.getName() }); } }
@Override public void emit() { Attributes attributes = new Attributes(); getBuilder().beginSpan(spanType, attributes); if (nesting) { getMarkupLanguage().emitMarkupLine(parser, state, getStart(this), getContent(this), 0); } else { getMarkupLanguage().emitMarkupText(parser, state, getContent(this)); } getBuilder().endSpan(); } }
@Override public int processLineContent(String line, int offset) { if (blockLineCount++ == 0) { offset = matcher.start(1); ((TWikiLanguage) markupLanguage).setLiteralMode(true); builder.beginBlock(BlockType.PARAGRAPH, new Attributes()); } else { Matcher endMatcher = endPattern.matcher(line); if (endMatcher.matches()) { setClosed(true); return endMatcher.start(1); } } markupLanguage.emitMarkupLine(parser, state, line, offset); builder.characters("\n"); //$NON-NLS-1$ return -1; }