Search in sources :

Example 1 with MarkdownParser

use of org.intellij.markdown.parser.MarkdownParser in project intellij-plugins by JetBrains.

the class MarkdownLazyElementType method doParseContents.

@Override
protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull PsiElement psi) {
    final Project project = psi.getProject();
    final Lexer lexer = new MarkdownLexerAdapter();
    final CharSequence chars = chameleon.getChars();
    final org.intellij.markdown.ast.ASTNode node = new MarkdownParser(MarkdownParserManager.FLAVOUR).parseInline(MarkdownElementType.markdownType(chameleon.getElementType()), chars, 0, chars.length());
    final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, lexer, getLanguage(), chars);
    assert builder.getCurrentOffset() == 0;
    new PsiBuilderFillingVisitor(builder).visitNode(node);
    assert builder.eof();
    return builder.getTreeBuilt().getFirstChildNode();
}
Also used : Project(com.intellij.openapi.project.Project) Lexer(com.intellij.lexer.Lexer) MarkdownLexerAdapter(org.intellij.plugins.markdown.lang.lexer.MarkdownLexerAdapter) PsiBuilder(com.intellij.lang.PsiBuilder) MarkdownParser(org.intellij.markdown.parser.MarkdownParser) PsiBuilderFillingVisitor(org.intellij.plugins.markdown.lang.parser.PsiBuilderFillingVisitor)

Example 2 with MarkdownParser

use of org.intellij.markdown.parser.MarkdownParser 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 3 with MarkdownParser

use of org.intellij.markdown.parser.MarkdownParser 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)

Aggregations

MarkdownParser (org.intellij.markdown.parser.MarkdownParser)3 ASTNode (org.intellij.markdown.ast.ASTNode)2 PsiBuilder (com.intellij.lang.PsiBuilder)1 Lexer (com.intellij.lexer.Lexer)1 Project (com.intellij.openapi.project.Project)1 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 MarkdownLexerAdapter (org.intellij.plugins.markdown.lang.lexer.MarkdownLexerAdapter)1 PsiBuilderFillingVisitor (org.intellij.plugins.markdown.lang.parser.PsiBuilderFillingVisitor)1 NotNull (org.jetbrains.annotations.NotNull)1