GithubHelp home page GithubHelp logo

markedj's Introduction

markedj build Maven Central License

JVM port of graceful markdown processor marked.js.

Usage

First, add following dependency into your pom.xml:

<dependencies>
  <dependency>
    <groupId>io.github.gitbucket</groupId>
    <artifactId>markedj</artifactId>
    <version>1.0.20</version>
  </dependency>
</dependencies>

You can easily use markedj via io.github.gitbucket.markedj.Marked:

import io.github.gitbucket.markedj.*;

String markdown = ...

// With default options
String html1 = Marked.marked(markdown);

// Specify options
Options options = new Options();
options.setSanitize(true);

String html2 = Marked.marked(markdown, options);

Options

io.github.gitbucket.markedj.Options has following properties to control Markdown conversion:

Name Default Description
gfm true Enable GitHub Flavored Markdown.
tables true Enable GFM tables. This option requires the gfm option to be true.
breaks false Enable GFM line breaks. This option requires the gfm option to be true.
sanitize false Ignore any HTML that has been input.
langPrefix "lang-" Prefix of class attribute of code block
headerPrefix "" Prefix of id attribute of header
safelist See Options.java Safelist of HTML tags.
extensions empty Extensions. See Extensions section

By default, markedj uses Jsoup's safelist mechanism for HTML rendering. It restricts renderable tags, attributes and even protocols of attribute values. For example, the image url must be http:// or https:// by default. You can remove this restriction by customizing the safelist as follows:

String html1 = Marked.marked("![alt text](/img/some-image.png \"title\")");
  // => <p><img alt=\"alt text\" title=\"title\"></p>

Options options = new Options();
options.getSafelist().removeProtocols("img", "src", "http", "https");

String html2 = Marked.marked("![alt text](/img/some-image.png \"title\")", options);
  // => <p><img src="/img/some-image.png" alt="alt text" title="title"></p>

Extensions

Markedj can be extended by implementing custom extensions. Extensions can be used by adding them to the options.

Options options = new Options();
options.addExtension(new GFMAlertExtension());
String html = Marked.marked("> [!NOTE]\n> This is a note!", options);

GFMAlert extension

Support for github like alerts.

For styling, some project-specific CSS is required.

Options options = new Options();
// Override default title for note alert
GFMAlertOptions alertOptions = new GFMAlertOptions();
alertOptions.setTitle(GFMAlerts.Alert.WARNING, "Attention!!!");
GFMAlertExtension gfmAlerts = new GFMAlertExtension(alertOptions);
options.addExtension(gfmAlerts);
String html = Marked.marked("> [!NOTE]\n> This is a note!", options);

Supported alert types are NOTE, TOP, IMPORTANT, WARNING, and CAUTION. Here is a Markdown example:

> [!NOTE]
> Useful information that users should know, even when skimming content.

This is translated to the following HTML:

<div class="markdown-alert markdown-alert-note">
  <p class="markdown-alert-title">Note</p>
  <p>Useful information that users should know, even when skimming content.</p>
</div>

Generated HTML can be customized by implementing your own renderer. DefaultGFMAlertRenderer is used by default.

for Developers

Release

Run the following command to upload artifacts to sonatype:

mvn clean deploy -DperformRelease=true

Then, go to https://oss.sonatype.org/, close and release the staging repository.

markedj's People

Contributors

backpaper0 avatar dependabot[bot] avatar macmarrum avatar makenowjust avatar mcfoggy avatar takezoe avatar thmarx avatar xuwei-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

markedj's Issues

Safety HTML tag rendering

Currently, markedj allows whitelist based HTML tag rendering. However it should be more safety by assist missing end tag.

Different renderings comapared to original marked.js or github style

Hi~ thank you for your markedj lib. : )

I'm trying to use it, but I have found some different rendering results.

Tested strings are

Message A
- list A
- List B

markedJ results is..

image

github or marked.js rendering is

Message A

  • list A
  • List B

Is it bug? or do I use it wrong?

img src attr ignored if not prefixed with http(s)?

Sorry if this is a known issue.

Observed

(import io.github.gitbucket.markedj.Marked)

(Marked/marked "![alt text](/img/some-image.png \"title\")")
=>
"<p><img alt=\"alt text\" title=\"title\"></p>"

Expected (as in how markedjs behaves)

(import io.github.gitbucket.markedj.Marked)

(Marked/marked "![alt text](/img/some-image.png \"title\")")
=>
"<p><img src=img/some-image.png alt=\"alt text\" title=\"title\"></p>"

add support for notification paragraphs

Would be great to add support for notifications paragraphs with a simple syntax like the quote one.

Thus it would be possible to render text like

image

using a simple syntax like:

! This is an info message.
!v This is a success message.
!! Consider this a warning.
!x This is an error message.

rendered text would look like

<div class="notification_info">This is an info message.</div>
<div class="notification_success">This is a success message.</div>
<div class="notification_warning">Consider this a warning.</div>
<div class="notification_error">This is an error message.</div>

then client of the library (gitbucket in our first case) could introduce CSS as defined here

Borders don't appear for blank table cells

When a table cell is blank, <td></td> is not output for the cell, causing its borders not to show up.

|ID|name|note|
|-|-|-|
|1|foo|This is foo|
|2|bar||
|3|fizz|This is fizz|
|4|buzz||

2016-05-11 18 46 57

Outputted HTML:

<table>
  <thead>
    <tr><th>ID</th><th>name</th><th>note</th></tr>
  </thead>
  <tbody>
    <tr><td>1</td><td>foo</td><td>This is foo</td></tr>
    <tr><td>2</td><td>bar</td></tr><tr>
    <td>3</td><td>fizz</td><td>This is fizz</td></tr>
    <tr><td>4</td><td>buzz</td></tr>
  </tbody>
</table>

ver 1.0.3 StackOverflowError

Environment
  • Windows 10 Pro
  • JDK 1.8.0_51
Reproduction code
StackTrace
java.lang.StackOverflowError
    at java.util.regex.Pattern$BranchConn.match(Unknown Source)
    at java.util.regex.Pattern$CharProperty.match(Unknown Source)
    at java.util.regex.Pattern$Branch.match(Unknown Source)
    at java.util.regex.Pattern$GroupHead.match(Unknown Source)
    at java.util.regex.Pattern$LazyLoop.match(Unknown Source)
    at java.util.regex.Pattern$GroupTail.match(Unknown Source)
    at java.util.regex.Pattern$BranchConn.match(Unknown Source)
    at java.util.regex.Pattern$CharProperty.match(Unknown Source)
    at java.util.regex.Pattern$Branch.match(Unknown Source)
    at java.util.regex.Pattern$GroupHead.match(Unknown Source)
    at java.util.regex.Pattern$LazyLoop.match(Unknown Source)
    at java.util.regex.Pattern$GroupTail.match(Unknown Source)
    at java.util.regex.Pattern$BranchConn.match(Unknown Source)
    at java.util.regex.Pattern$CharProperty.match(Unknown Source)
    at java.util.regex.Pattern$Branch.match(Unknown Source)
    at java.util.regex.Pattern$GroupHead.match(Unknown Source)
    at java.util.regex.Pattern$LazyLoop.match(Unknown Source)
    at java.util.regex.Pattern$GroupTail.match(Unknown Source)
    at java.util.regex.Pattern$BranchConn.match(Unknown Source)
    at java.util.regex.Pattern$CharProperty.match(Unknown Source)
    at java.util.regex.Pattern$Branch.match(Unknown Source)
    at java.util.regex.Pattern$GroupHead.match(Unknown Source)
    at java.util.regex.Pattern$LazyLoop.match(Unknown Source)
    at java.util.regex.Pattern$GroupTail.match(Unknown Source)
    at java.util.regex.Pattern$BranchConn.match(Unknown Source)
    at java.util.regex.Pattern$CharProperty.match(Unknown Source)
    at java.util.regex.Pattern$Branch.match(Unknown Source)
    at java.util.regex.Pattern$GroupHead.match(Unknown Source)
    at java.util.regex.Pattern$LazyLoop.match(Unknown Source)
    at java.util.regex.Pattern$GroupTail.match(Unknown Source)
    at java.util.regex.Pattern$BranchConn.match(Unknown Source)
    at java.util.regex.Pattern$CharProperty.match(Unknown Source)
    at java.util.regex.Pattern$Branch.match(Unknown Source)
    at java.util.regex.Pattern$GroupHead.match(Unknown Source)
    at java.util.regex.Pattern$LazyLoop.match(Unknown Source)
    at java.util.regex.Pattern$GroupTail.match(Unknown Source)
    at java.util.regex.Pattern$BranchConn.match(Unknown Source)
    at java.util.regex.Pattern$CharProperty.match(Unknown Source)
    at java.util.regex.Pattern$Branch.match(Unknown Source)
    at java.util.regex.Pattern$GroupHead.match(Unknown Source)
...

">" in blockquote not show

I'm using gitbucket 4.0, and have a problem in rendering README.md:

> **File > Settings > Install JetBrains plugin** was rendered to

FileSettingsInstall JetBrains plugin

which should be

File > Settings > Install JetBrains plugin

Support escaped round brackets in markdown links

If round brackets are contained in the links, there are different ways of entering them in markdown. They are discussed at https://stackoverflow.com/questions/13824669/how-do-you-write-a-link-containing-a-closing-bracket-in-markdown-syntax.

[Syntax](http://en.wikipedia.org/wiki/Syntax_\(programming_languages\))
[Syntax](<https://en.wikipedia.org/wiki/Slowloris_(computer_security)>)
[Syntax](http://en.wikipedia.org/wiki/Syntax_%28programming_languages%29)

Currently markedj seems to support only the third way. It would be nice if also the other ways could be supported.

Related: freeplane/freeplane#1847

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.