Package org.pegdown.ast

Examples of org.pegdown.ast.RootNode


                if ( !first )
                {
                    text = text.substring( metadataMatcher.end() );
                }
            }
            RootNode rootNode = PEGDOWN_PROCESSOR.parseMarkdown( text.toCharArray() );
            if ( !haveTitle && rootNode.getChildren().size() > 0 )
            {
                // use the first (non-comment) node only if it is a heading
                int i = 0;
                Node firstNode = null;
                while ( i < rootNode.getChildren().size() && isHtmlComment(
                    ( firstNode = rootNode.getChildren().get( i ) ) ) )
                {
                    i++;
                }
                if ( firstNode instanceof HeaderNode )
                {
View Full Code Here


    public void parse( Reader source, Sink sink )
        throws ParseException
    {
        try
        {
            RootNode rootNode = PEGDOWN_PROCESSOR.parseMarkdown( IOUtil.toString( source ).toCharArray() );
            String markdownAsHtml = new MarkdownToDoxiaHtmlSerializer().toHtml( rootNode );
            super.parse( new StringReader( "<html><body>" + markdownAsHtml + "</body></html>" ), sink );
        }
        catch ( IOException e )
        {
View Full Code Here

    }
  }

  public byte[] markdownToDocHtml(String md, String charEnc)
      throws UnsupportedEncodingException {
    RootNode root = parseMarkdown(md);
    String title = findTitle(root);

    StringBuilder html = new StringBuilder();
    html.append("<html>");
    html.append("<head>");
View Full Code Here

   * @throws java.text.ParseException
   */
  public static String transformMarkdown(String markdown, LinkRenderer linkRenderer) {
    try {
      PegDownProcessor pd = new PegDownProcessor(ALL & ~SMARTYPANTS);
      RootNode astRoot = pd.parseMarkdown(markdown.toCharArray());
      return new WorkaroundHtmlSerializer(linkRenderer == null ? new LinkRenderer() : linkRenderer).toHtml(astRoot);
    } catch (ParsingTimeoutException e) {
      return null;
    }
  }
View Full Code Here

   * @throws java.text.ParseException
   */
  public static String transformMarkdown(String markdown, LinkRenderer linkRenderer) {
    try {
      PegDownProcessor pd = new PegDownProcessor(ALL & ~SMARTYPANTS);
      RootNode astRoot = pd.parseMarkdown(markdown.toCharArray());
      return new WorkaroundHtmlSerializer(linkRenderer == null ? new LinkRenderer() : linkRenderer).toHtml(astRoot);
    } catch (ParsingTimeoutException e) {
      return null;
    }
  }
View Full Code Here

                if ( !first )
                {
                    text = text.substring( metadataMatcher.end() );
                }
            }
            RootNode rootNode = PEGDOWN_PROCESSOR.parseMarkdown( text.toCharArray() );
            if ( !haveTitle && rootNode.getChildren().size() > 0 )
            {
                // use the first (non-comment) node only if it is a heading
                int i = 0;
                Node firstNode = null;
                while ( i < rootNode.getChildren().size() && isHtmlComment(
                    ( firstNode = rootNode.getChildren().get( i ) ) ) )
                {
                    i++;
                }
                if ( firstNode instanceof HeaderNode )
                {
View Full Code Here

    }

    public void runTestWithExtensions(String baseName, int extensions) throws IOException {
        String source = getTestResourceAsString(baseName + ".md");
        PegDownProcessor processor = new PegDownProcessor(extensions);
        RootNode rootNode = processor.parseMarkdown(source.toCharArray());

        assertThat("rootNode", rootNode, notNullValue());

        final int totalLength = source.length();
        MarkdownTokenListBuilder builder = new MarkdownTokenListBuilder(totalLength);
        MarkdownLexerVisitor visitor = new MarkdownLexerVisitor(builder);
        rootNode.accept(visitor);
        List<MarkdownToken> tokens = builder.build();
       
        assertThat(tokens, everyItem(nonZeroLength()));
        assertThat(totalLengthOf(tokens), equalTo(totalLength));
    }
View Full Code Here

        int inputLength = markdownSource.length;

        List<MarkdownToken> tokens;
        try {
            RootNode rootNode = markdownProcessor.parseMarkdown(markdownSource);

            MarkdownTokenListBuilder builder = new MarkdownTokenListBuilder(inputLength);
            MarkdownLexerVisitor visitor = new MarkdownLexerVisitor(builder);
            rootNode.accept(visitor);
            tokens = builder.build();
        }
        catch (ParsingTimeoutException ex) {
            LOG.log(Level.WARNING, "Time out while parsing Markdown source, falling back to no highlighting");
            tokens = Collections.singletonList(new MarkdownToken(MarkdownTokenId.PLAIN, 0, inputLength));
View Full Code Here

    public List<? extends StructureItem> scan(ParserResult pr) {
        List<? extends StructureItem> items = null;
        if (pr instanceof MarkdownParserResult) {
            MarkdownParserResult result = (MarkdownParserResult) pr;
            try {
                RootNode rootNode = result.getRootNode();
                int extensions = result.getExtensions();
                if (rootNode != null) {
                    FileObject file = pr.getSnapshot().getSource().getFileObject();
                    MarkdownTOCVisitor visitor = new MarkdownTOCVisitor(file);
                    rootNode.accept(visitor);
                    MarkdownTOCRootItem tocRootItem
                            = new MarkdownTOCRootItem(file, rootNode, visitor.getTOCEntryItems());
                    MarkdownReferencesRootItem refsRootItem
                            = new MarkdownReferencesRootItem(file, rootNode);
View Full Code Here

    public Map<String, List<OffsetRange>> folds(ParserResult pr) {
        Map<String, List<OffsetRange>> foldsByType = null;
        if (pr instanceof MarkdownParserResult) {
            MarkdownParserResult result = (MarkdownParserResult) pr;
            try {
                RootNode rootNode = result.getRootNode();
                if (rootNode != null) {
                    List<OffsetRange> sectionFolds = new ArrayList<OffsetRange>();
                    for (Node node : rootNode.getChildren()) {
                        MarkdownTOCVisitor visitor = new MarkdownTOCVisitor(pr.getSnapshot().getSource().getFileObject());
                        rootNode.accept(visitor);
                        sectionFolds = visitor.getOffsetRanges();
                    }
                    foldsByType = Collections.singletonMap("comments", sectionFolds);
                }
            }
View Full Code Here

TOP

Related Classes of org.pegdown.ast.RootNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.