diff options
Diffstat (limited to 'org.eclipse.mylyn.wikitext.markdown.core/src/org/eclipse/mylyn/internal/wikitext/markdown/core/block/QuoteBlock.java')
-rw-r--r-- | org.eclipse.mylyn.wikitext.markdown.core/src/org/eclipse/mylyn/internal/wikitext/markdown/core/block/QuoteBlock.java | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/org.eclipse.mylyn.wikitext.markdown.core/src/org/eclipse/mylyn/internal/wikitext/markdown/core/block/QuoteBlock.java b/org.eclipse.mylyn.wikitext.markdown.core/src/org/eclipse/mylyn/internal/wikitext/markdown/core/block/QuoteBlock.java index 3972da19e..40f53a2b3 100644 --- a/org.eclipse.mylyn.wikitext.markdown.core/src/org/eclipse/mylyn/internal/wikitext/markdown/core/block/QuoteBlock.java +++ b/org.eclipse.mylyn.wikitext.markdown.core/src/org/eclipse/mylyn/internal/wikitext/markdown/core/block/QuoteBlock.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Stefan Seelmann and others. + * Copyright (c) 2012, 2013 Stefan Seelmann and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -23,11 +23,11 @@ import org.eclipse.mylyn.wikitext.core.parser.markup.Block; * * @author Stefan Seelmann */ -public class QuoteBlock extends Block { +public class QuoteBlock extends NestableBlock { - private static final Pattern startPattern = Pattern.compile(">\\s*(.*)"); //$NON-NLS-1$ + private static final Pattern startPattern = Pattern.compile(">\\s?(.*)"); //$NON-NLS-1$ - private static final Pattern linePattern = Pattern.compile("(?:>\\s*)?(.*)"); //$NON-NLS-1$ + private static final Pattern linePattern = Pattern.compile("(?:>\\s?)?(.*)"); //$NON-NLS-1$ private int blockLineCount = 0; @@ -35,59 +35,74 @@ public class QuoteBlock extends Block { @Override public boolean canStart(String line, int lineOffset) { - if (lineOffset == 0) { - return startPattern.matcher(line).matches(); - } else { - return false; - } + return startPattern.matcher(line.substring(lineOffset)).matches(); } @Override protected int processLineContent(String line, int offset) { + String text = line.substring(offset); // start of block if (blockLineCount == 0) { builder.beginBlock(BlockType.QUOTE, new Attributes()); } // empty line: end of block - if (markupLanguage.isEmptyLine(line)) { + if (markupLanguage.isEmptyLine(text)) { setClosed(true); - return 0; + return offset; } // extract the content - Matcher matcher = linePattern.matcher(line); + Matcher matcher = linePattern.matcher(text); if (!matcher.matches()) { setClosed(true); - return 0; + return offset; } - String content = matcher.group(1); + int contentStart = offset + matcher.start(1); - // determine nested block, at least the paragraph block must match - for (Block block : getMarkupLanguage().getBlocks()) { - if (block.canStart(content, 0)) { - if (nestedBlock != null && nestedBlock.getClass() != block.getClass()) { - nestedBlock.setClosed(true); + if (nestedBlock != null) { + if (!(nestedBlock instanceof QuoteBlock) && this.canStart(line, contentStart)) { + nestedBlock.setClosed(true); + nestedBlock = null; + processNextBlock(line, contentStart); + } else { + int processed = nestedBlock.processLine(line, contentStart); + if (nestedBlock.isClosed()) { nestedBlock = null; + if (processed >= contentStart && processed < line.length()) { + processNextBlock(line, contentStart); + } } - if (nestedBlock == null) { - nestedBlock = block.clone(); - nestedBlock.setParser(getParser()); - nestedBlock.setState(getState()); - } - break; } + } else { + processNextBlock(line, contentStart); } + blockLineCount++; + return -1; + } + + private void processNextBlock(String line, int contentStart) { + // determine nested block, at least the paragraph block must match + for (Block block : getMarkupLanguage().getBlocks()) { + if (block.canStart(line, contentStart)) { + nestedBlock = clone(block); + break; + } + } // delegate content processing to nested block - nestedBlock.processLine(content, 0); + nestedBlock.processLine(line, contentStart); if (nestedBlock.isClosed()) { nestedBlock = null; } + } - blockLineCount++; - return -1; + private Block clone(Block block) { + Block clonedBlock = block.clone(); + clonedBlock.setParser(getParser()); + clonedBlock.setState(getState()); + return clonedBlock; } @Override |