org.commonmark.node.FencedCodeBlock Java Examples
The following examples show how to use
org.commonmark.node.FencedCodeBlock.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RuleService.java From clouditor with Apache License 2.0 | 6 votes |
@Override public void visit(FencedCodeBlock fencedCodeBlock) { if (fencedCodeBlock.getInfo().equals("ccl")) { var code = fencedCodeBlock.getLiteral(); // parse CCL // for now, one line is one condition, later me might have more complex statements var lines = code.split("\\n"); for (var line : lines) { // TODO: this should actually be handled by the grammar if (!line.startsWith("#")) { var condition = new CCLDeserializer().parse(line); this.rule.addCondition(condition); } } } else { super.visit(fencedCodeBlock); } }
Example #2
Source File: MarkdownUtil.java From ml-blog with MIT License | 6 votes |
@Override public void render(Node node) { HtmlWriter html = context.getWriter(); FencedCodeBlock codeBlock = (FencedCodeBlock) node; Map<String,String> attrs = new HashMap<>(); if (!StringUtils.isEmpty(codeBlock.getInfo())) { attrs.put("class","language-" + codeBlock.getInfo()); } html.line(); html.tag("pre"); html.tag("code",attrs); html.tag("ol"); String data = codeBlock.getLiteral(); String[] split = data.split("\n"); for (String s : split) { html.tag("li"); html.text(s + "\n"); html.tag("/li"); } html.tag("/ol"); html.tag("/code"); html.tag("/pre"); html.line(); }
Example #3
Source File: CorePlugin.java From Markwon with Apache License 2.0 | 6 votes |
@Override public void configureSpansFactory(@NonNull MarkwonSpansFactory.Builder builder) { // reuse this one for both code-blocks (indent & fenced) final CodeBlockSpanFactory codeBlockSpanFactory = new CodeBlockSpanFactory(); builder .setFactory(StrongEmphasis.class, new StrongEmphasisSpanFactory()) .setFactory(Emphasis.class, new EmphasisSpanFactory()) .setFactory(BlockQuote.class, new BlockQuoteSpanFactory()) .setFactory(Code.class, new CodeSpanFactory()) .setFactory(FencedCodeBlock.class, codeBlockSpanFactory) .setFactory(IndentedCodeBlock.class, codeBlockSpanFactory) .setFactory(ListItem.class, new ListItemSpanFactory()) .setFactory(Heading.class, new HeadingSpanFactory()) .setFactory(Link.class, new LinkSpanFactory()) .setFactory(ThematicBreak.class, new ThematicBreakSpanFactory()); }
Example #4
Source File: CommonmarkPreviewRenderer.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 6 votes |
private void printAttributes(StringBuilder buf, Node node) { if (node instanceof Text) printAttribute(buf, "literal", ((Text)node).getLiteral()); else if (node instanceof Code) printAttribute(buf, "literal", ((Code)node).getLiteral()); else if (node instanceof IndentedCodeBlock) printAttribute(buf, "literal", ((IndentedCodeBlock)node).getLiteral()); else if (node instanceof FencedCodeBlock) printAttribute(buf, "literal", ((FencedCodeBlock)node).getLiteral()); else if (node instanceof HtmlBlock) printAttribute(buf, "literal", ((HtmlBlock)node).getLiteral()); else if (node instanceof HtmlInline) printAttribute(buf, "literal", ((HtmlInline)node).getLiteral()); else if (node instanceof Link) { printAttribute(buf, "destination", ((Link)node).getDestination()); printAttribute(buf, "title", ((Link)node).getTitle()); } else if (node instanceof Image) { printAttribute(buf, "destination", ((Image)node).getDestination()); printAttribute(buf, "title", ((Image)node).getTitle()); } else if (node instanceof Heading) printAttribute(buf, "level", ((Heading)node).getLevel()); }
Example #5
Source File: CorePlugin.java From Markwon with Apache License 2.0 | 5 votes |
/** * @return a set with enabled by default block types * @since 4.4.0 */ @NonNull public static Set<Class<? extends Block>> enabledBlockTypes() { return new HashSet<>(Arrays.asList( BlockQuote.class, Heading.class, FencedCodeBlock.class, HtmlBlock.class, ThematicBreak.class, ListBlock.class, IndentedCodeBlock.class )); }
Example #6
Source File: RecyclerActivity.java From Markwon with Apache License 2.0 | 5 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_recycler); // create MarkwonAdapter and register two blocks that will be rendered differently // * fenced code block (can also specify the same Entry for indended code block) // * table block final MarkwonAdapter adapter = MarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text) // we can simply use bundled SimpleEntry .include(FencedCodeBlock.class, SimpleEntry.create(R.layout.adapter_fenced_code_block, R.id.text)) .include(TableBlock.class, TableEntry.create(builder -> builder .tableLayout(R.layout.adapter_table_block, R.id.table_layout) .textLayoutIsRoot(R.layout.view_table_entry_cell))) .build(); final RecyclerView recyclerView = findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setHasFixedSize(true); recyclerView.setAdapter(adapter); final Markwon markwon = markwon(this); adapter.setMarkdown(markwon, loadReadMe(this)); // please note that we should notify updates (adapter doesn't do it implicitly) adapter.notifyDataSetChanged(); }
Example #7
Source File: FencedCodeBlockParserTest.java From commonmark-java with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void backtickInfo() { Node document = PARSER.parse("```info ~ test\ncode\n```"); FencedCodeBlock codeBlock = (FencedCodeBlock) document.getFirstChild(); assertEquals("info ~ test", codeBlock.getInfo()); assertEquals("code\n", codeBlock.getLiteral()); }
Example #8
Source File: MarkdownUtil.java From ml-blog with MIT License | 4 votes |
@Override public Set<Class<? extends Node>> getNodeTypes() { return Collections.singleton(FencedCodeBlock.class); }
Example #9
Source File: MarkwonVisitorImpl.java From Markwon with Apache License 2.0 | 4 votes |
@Override public void visit(FencedCodeBlock fencedCodeBlock) { visit((Node) fencedCodeBlock); }