Search in sources :

Example 1 with ASTNode

use of org.intellij.markdown.ast.ASTNode in project intellij-plugins by JetBrains.

the class MarkdownParserManager method parseContent.

public static ASTNode parseContent(@NotNull CharSequence buffer) {
    final ParsingInfo info = ourLastParsingResult.get();
    if (info != null && info.myBufferHash == buffer.hashCode() && info.myBuffer.equals(buffer)) {
        return info.myParseResult;
    }
    final ASTNode parseResult = new MarkdownParser(FLAVOUR).parse(MarkdownElementTypes.MARKDOWN_FILE, buffer.toString(), false);
    ourLastParsingResult.set(new ParsingInfo(buffer, parseResult));
    return parseResult;
}
Also used : ASTNode(org.intellij.markdown.ast.ASTNode) MarkdownParser(org.intellij.markdown.parser.MarkdownParser)

Example 2 with ASTNode

use of org.intellij.markdown.ast.ASTNode in project intellij-plugins by JetBrains.

the class MarkdownPreviewFileEditor method generateMarkdownHtml.

@NotNull
private static String generateMarkdownHtml(@NotNull VirtualFile file, @NotNull String text) {
    final VirtualFile parent = file.getParent();
    final URI baseUri = parent != null ? new File(parent.getPath()).toURI() : null;
    final ASTNode parsedTree = new MarkdownParser(MarkdownParserManager.FLAVOUR).buildMarkdownTreeFromString(text);
    final Map<IElementType, GeneratingProvider> htmlGeneratingProviders = MarkdownParserManager.FLAVOUR.createHtmlGeneratingProviders(LinkMap.Builder.buildLinkMap(parsedTree, text), baseUri);
    return new HtmlGenerator(text, parsedTree, htmlGeneratingProviders, true).generateHtml();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IElementType(org.intellij.markdown.IElementType) GeneratingProvider(org.intellij.markdown.html.GeneratingProvider) ASTNode(org.intellij.markdown.ast.ASTNode) HtmlGenerator(org.intellij.markdown.html.HtmlGenerator) URI(java.net.URI) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) MarkdownParser(org.intellij.markdown.parser.MarkdownParser) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ASTNode

use of org.intellij.markdown.ast.ASTNode in project intellij-plugins by JetBrains.

the class MarkdownToplevelLexer method start.

@Override
public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) {
    myBuffer = buffer;
    myBufferStart = startOffset;
    myBufferEnd = endOffset;
    final ASTNode parsedTree = MarkdownParserManager.parseContent(buffer.subSequence(startOffset, endOffset));
    myLexemes = new ArrayList<>();
    myStartOffsets = new ArrayList<>();
    myEndOffsets = new ArrayList<>();
    ASTNodeKt.accept(parsedTree, new LexerBuildingVisitor());
    myLexemeIndex = 0;
}
Also used : ASTNode(org.intellij.markdown.ast.ASTNode)

Aggregations

ASTNode (org.intellij.markdown.ast.ASTNode)3 MarkdownParser (org.intellij.markdown.parser.MarkdownParser)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 URI (java.net.URI)1 IElementType (org.intellij.markdown.IElementType)1 GeneratingProvider (org.intellij.markdown.html.GeneratingProvider)1 HtmlGenerator (org.intellij.markdown.html.HtmlGenerator)1 NotNull (org.jetbrains.annotations.NotNull)1