org.eclipse.mylyn.wikitext.core.parser.markup
Class MarkupLanguage

java.lang.Object
  extended by org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
AbstractMarkupLanguage

public abstract class MarkupLanguage
extends Object
implements Cloneable

A markup language, which knows its formatting rules and is able to process content based on Block, PatternBasedElementProcessor and PatternBasedElement concepts. All markup languages supported by WikiText extend this class.

The MarkupLanguage class provides basic functionality for determining which blocks process which markup content in a particular document. In general multi-line documents are split into consecutive regions called blocks, and each line in a block is processed with spanning sections called phrase modifiers, and tokens within a span are replaced with their respective replacement tokens. These rules apply to most lightweight markup languages, however subclasses may override this default functionality if required. For example, by default phrase modifiers are non-overlapping and non-nested, however if required a subclass could permit such nesting.

Generally markup language classes are not accessed directly by client code, instead client code should configure and call MarkupParser, accessing the markup language by name using the ServiceLocator.

Author:
David Green

Nested Class Summary
static class MarkupLanguage.PatternBasedSyntax
           
 
Field Summary
protected  MarkupLanguageConfiguration configuration
           
protected  String internalLinkPattern
           
 
Constructor Summary
MarkupLanguage()
           
 
Method Summary
 MarkupLanguage clone()
           
 void configure(MarkupLanguageConfiguration configuration)
          configure the markup language with a configuration that may alter the language syntax and capabilities.
protected  ContentState createState()
          Create new state for tracking a document and its contents during a parse session.
 void emitMarkupLine(MarkupParser parser, ContentState state, int textLineOffset, String line, int offset)
          Emit a markup line that may contain phrase modifiers and replacement tokens, but no block modifiers.
 void emitMarkupLine(MarkupParser parser, ContentState state, String line, int offset)
          Emit a markup line that may contain phrase modifiers and replacement tokens, but no block modifiers.
 void emitMarkupText(MarkupParser parser, ContentState state, String text)
          Emit markup that may contain replacement tokens but no phrase or block modifiers.
abstract  List<Block> getBlocks()
           
 String getExtendsLanguage()
          The name of the markup language that is extended by this one
 IdGenerationStrategy getIdGenerationStrategy()
          get the id strategy employed by this markup language.
 String getInternalLinkPattern()
          The pattern to use when creating hyperlink targets for internal links.
 String getName()
          The name of the markup language, typically the same as the name of the markup language supported by this markup language.
protected abstract  MarkupLanguage.PatternBasedSyntax getPhraseModifierSyntax()
           
protected abstract  MarkupLanguage.PatternBasedSyntax getReplacementTokenSyntax()
           
protected abstract  void initializeSyntax()
          initialize the syntax of the markup language.
 boolean isBlocksOnly()
          indicate if the parser should detect blocks only.
 boolean isDetectingRawHyperlinks()
          Indicate if this markup language detects 'raw' hyperlinks; that is hyperlinks without any special markup.
 boolean isEmptyLine(String line)
          indicate if the given line is considered 'empty'.
 boolean isEnableMacros()
          Indicate if macro processing is enabled.
 boolean isFilterGenerativeContents()
          Indicate if generative contents should be filtered.
 void processContent(MarkupParser parser, String markupContent, boolean asDocument)
           
 void setBlocksOnly(boolean blocksOnly)
          indicate if the parser should detect blocks only.
 void setEnableMacros(boolean enableMacros)
          Indicate if macro processing is enabled.
 void setExtendsLanguage(String extendsLanguage)
          The name of the markup language that is extended by this one
 void setFilterGenerativeContents(boolean filterGenerativeBlocks)
          Indicate if table of contents should be filtered.
 void setInternalLinkPattern(String internalLinkPattern)
          The pattern to use when creating hyperlink targets for internal links.
 void setName(String name)
          The name of the markup language, typically the same as the name of the markup language supported by this markup language.
 Block startBlock(String line, int lineOffset)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

internalLinkPattern

protected String internalLinkPattern

configuration

protected MarkupLanguageConfiguration configuration
Constructor Detail

MarkupLanguage

public MarkupLanguage()
Method Detail

clone

public MarkupLanguage clone()
Overrides:
clone in class Object

createState

protected ContentState createState()
Create new state for tracking a document and its contents during a parse session. Subclasses may override this method to provide additional state tracking capability.

Returns:
the new state.

getIdGenerationStrategy

public IdGenerationStrategy getIdGenerationStrategy()
get the id strategy employed by this markup language.


processContent

public void processContent(MarkupParser parser,
                           String markupContent,
                           boolean asDocument)

startBlock

public Block startBlock(String line,
                        int lineOffset)

getBlocks

public abstract List<Block> getBlocks()

configure

public void configure(MarkupLanguageConfiguration configuration)
               throws UnsupportedOperationException
configure the markup language with a configuration that may alter the language syntax and capabilities.

Parameters:
configuration - the configuration to use
Throws:
UnsupportedOperationException - markup languages that do not support configuration must throw this exception.

initializeSyntax

protected abstract void initializeSyntax()
initialize the syntax of the markup language.


emitMarkupLine

public void emitMarkupLine(MarkupParser parser,
                           ContentState state,
                           int textLineOffset,
                           String line,
                           int offset)
Emit a markup line that may contain phrase modifiers and replacement tokens, but no block modifiers.

Parameters:
parser -
state -
textLineOffset - the offset of the provided text in the current line
line - the text to process
offset - the offset in the text at which processing should begin

emitMarkupLine

public void emitMarkupLine(MarkupParser parser,
                           ContentState state,
                           String line,
                           int offset)
Emit a markup line that may contain phrase modifiers and replacement tokens, but no block modifiers.

Parameters:
parser -
state -
line -
offset -

emitMarkupText

public void emitMarkupText(MarkupParser parser,
                           ContentState state,
                           String text)
Emit markup that may contain replacement tokens but no phrase or block modifiers.

Parameters:
parser -
state -
text -

getPhraseModifierSyntax

protected abstract MarkupLanguage.PatternBasedSyntax getPhraseModifierSyntax()

getReplacementTokenSyntax

protected abstract MarkupLanguage.PatternBasedSyntax getReplacementTokenSyntax()

getName

public String getName()
The name of the markup language, typically the same as the name of the markup language supported by this markup language. This value may be displayed to the user.

Returns:
the name, or null if unknown

setName

public void setName(String name)
The name of the markup language, typically the same as the name of the markup language supported by this markup language. This value may be displayed to the user.

Parameters:
name - the name

getExtendsLanguage

public String getExtendsLanguage()
The name of the markup language that is extended by this one

Returns:
the name, or null if this markup language does not extend another.

setExtendsLanguage

public void setExtendsLanguage(String extendsLanguage)
The name of the markup language that is extended by this one

Parameters:
extendsLanguage - the name, or null if this markup language does not extend another.

isFilterGenerativeContents

public boolean isFilterGenerativeContents()
Indicate if generative contents should be filtered. This option is used with the OutlineParser.


setFilterGenerativeContents

public void setFilterGenerativeContents(boolean filterGenerativeBlocks)
Indicate if table of contents should be filtered. This option is used with the OutlineParser.


isBlocksOnly

public boolean isBlocksOnly()
indicate if the parser should detect blocks only. This is useful for use in a document partitioner where the partition boundaries are defined by blocks.


setBlocksOnly

public void setBlocksOnly(boolean blocksOnly)
indicate if the parser should detect blocks only. This is useful for use in a document partitioner where the partition boundaries are defined by blocks.


isEmptyLine

public boolean isEmptyLine(String line)
indicate if the given line is considered 'empty'. The default implementation returns true for lines of length 0, and for lines whose only content is whitespace.

Parameters:
line - the line content
Returns:
true if the given line is considered empty by this markup language

getInternalLinkPattern

public String getInternalLinkPattern()
The pattern to use when creating hyperlink targets for internal links. The pattern is implementation-specific, however implementations are encouraged to use MessageFormat, where the 0th parameter is the internal link.

See Also:
MessageFormat

setInternalLinkPattern

public void setInternalLinkPattern(String internalLinkPattern)
The pattern to use when creating hyperlink targets for internal links. The pattern is implementation-specific, however implementations are encouraged to use MessageFormat, where the 0th parameter is the internal link.

See Also:
MessageFormat

isDetectingRawHyperlinks

public boolean isDetectingRawHyperlinks()
Indicate if this markup language detects 'raw' hyperlinks; that is hyperlinks without any special markup. The default implementation checks the markup syntax for use of ImpliedHyperlinkReplacementToken and returns true if it is in the syntax.

Returns:
true if raw hyperlinks are detected by this markup language, otherwise false.
Since:
1.1

isEnableMacros

public boolean isEnableMacros()
Indicate if macro processing is enabled. Generally such processing is enabled except when used in a source editor.

Macros are defined as text substitution prior to normal processing. Such preprocessing changes the markup before it is processed, and as such has the side-effect of changing computed offsets when parsing markup.

The default value is true.

Returns:
true if macros are enabled, otherwise false
Since:
1.3

setEnableMacros

public void setEnableMacros(boolean enableMacros)
Indicate if macro processing is enabled. Generally such processing is enabled except when used in a source editor.

Macros are defined as text substitution prior to normal processing. Such preprocessing changes the markup before it is processed, and as such has the side-effect of changing computed offsets when parsing markup.

Parameters:
enableMacros - true if macros are enabled, otherwise false
Since:
1.3


Copyright © 2011 FuseSource, Corp.. All Rights Reserved.