예제 #1
0
 /** Parse a Mediawiki heading of the form "==heading==" and return the resulting HTML output. */
 public String parse(JFlexLexer lexer, String raw, Object... args) throws ParserException {
   if (logger.isTraceEnabled()) {
     logger.trace("heading: " + raw + " (" + lexer.yystate() + ")");
   }
   // the wikiheading tag may match a preceding newline, so strip it
   raw = raw.trim();
   int level = this.generateTagLevel(raw, args);
   String tagText = this.generateTagText(raw, args);
   String tocText = this.buildTocText(lexer, tagText);
   String tagName = this.buildTagName(lexer, tocText);
   if (lexer.getMode() <= JFlexParser.MODE_SLICE) {
     String sectionName = StringEscapeUtils.unescapeHtml4(tocText);
     lexer.getParserOutput().setSectionName(sectionName);
     return raw;
   }
   if (!(lexer instanceof JAMWikiLexer)) {
     throw new IllegalStateException(
         "Cannot parse heading tags except with instances of JAMWikiLexer or in slice/splice mode");
   }
   JAMWikiLexer jamwikiLexer = (JAMWikiLexer) lexer;
   if (jamwikiLexer.paragraphIsOpen()) {
     // close any open paragraph
     jamwikiLexer.popTag("p");
   }
   return this.generateOutput(jamwikiLexer, tagName, tocText, tagText, level, raw, args);
 }
예제 #2
0
 private String generateOutput(
     JAMWikiLexer lexer,
     String tagName,
     String tocText,
     String tagText,
     int level,
     String raw,
     Object... args)
     throws ParserException {
   lexer
       .peekTag()
       .getTagContent()
       .append(this.updateToc(lexer.getParserInput(), tagName, tocText, level));
   int nextSection = lexer.getParserInput().getTableOfContents().size();
   String tagType = "h" + level;
   lexer.pushTag(tagType, this.generateTagOpen(raw, args));
   lexer
       .peekTag()
       .getTagContent()
       .append(this.buildSectionEditLink(lexer.getParserInput(), nextSection));
   String parsedTocText =
       this.processTocText(
           lexer.getParserInput(), lexer.getParserOutput(), tagText, lexer.getMode());
   lexer
       .peekTag()
       .getTagContent()
       .append("<span id=\"")
       .append(tagName)
       .append("\">")
       .append(parsedTocText)
       .append("</span>");
   lexer.popTag(tagType);
   return "";
 }