From edbb8ea68d39afc30f8966347d29894e13d1b9c9 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Wed, 9 Mar 2016 08:39:28 +0900 Subject: [PATCH 01/10] 1.0.7 release --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4c1e81d..d8b789e 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ At first, add following dependency into your `pom.xml`: io.github.gitbucket markedj - 1.0.6 + 1.0.7 ``` diff --git a/pom.xml b/pom.xml index 5ad031f..763dc88 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.gitbucket markedj jar - 1.0.7-SNAPSHOT + 1.0.7 markedj https://github.com/gitbucket/markedj JVM port of graceful markdown processor marked.js From c1fe4ed7bf03dd43a86b63d4ccc64a3f5d1cd855 Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Sat, 12 Mar 2016 17:47:38 +0900 Subject: [PATCH 02/10] Fix to look up case-insensitive reference link Current markedj converts the key of link definition to lower case, but it dosen't convert the key of reference link. It causes the key not to look up. See following Markdown: ```markdown [Foo] [Foo]: http://example.com ``` It yields to `

[Foo]

`, but the result we expected is `

Foo

` because the key `Foo` can't be looked up. I fixed the key of reference link is converted to lower case when looking it up from definitions. --- .../java/io/github/gitbucket/markedj/InlineLexer.java | 2 +- src/test/java/io/github/gitbucket/markedj/MarkedTest.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/gitbucket/markedj/InlineLexer.java b/src/main/java/io/github/gitbucket/markedj/InlineLexer.java index 6a1ce1a..7511b74 100644 --- a/src/main/java/io/github/gitbucket/markedj/InlineLexer.java +++ b/src/main/java/io/github/gitbucket/markedj/InlineLexer.java @@ -118,7 +118,7 @@ public String output(String src){ } else { key = cap.get(1).replaceAll("\\s+", ""); } - Lexer.Link link = links.get(key); + Lexer.Link link = links.get(key.toLowerCase()); if(link == null || isEmpty(link.getHref())){ out.append(renderer.nolink(cap.get(0))); continue; diff --git a/src/test/java/io/github/gitbucket/markedj/MarkedTest.java b/src/test/java/io/github/gitbucket/markedj/MarkedTest.java index 1cff0c8..33e5e6b 100644 --- a/src/test/java/io/github/gitbucket/markedj/MarkedTest.java +++ b/src/test/java/io/github/gitbucket/markedj/MarkedTest.java @@ -45,6 +45,12 @@ public void testAutolink() throws Exception { assertEquals("

takezoe@gmail.com

\n", result); } + @Test + public void testReflink() throws Exception { + String result = Marked.marked("[FOO], [bar][Foo], [Bar]\n\n[Foo]: http://example.com"); + assertEquals("

FOO, bar, [Bar]

\n", result); + } + @Test public void testEm() throws Exception { { @@ -151,4 +157,4 @@ private String loadResourceAsString(String path) throws IOException { in.close(); } } -} \ No newline at end of file +} From 73dbf37960afbcd79ce1538f35199bf5a6041fa5 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sun, 17 Apr 2016 22:27:52 +0900 Subject: [PATCH 03/10] Fix grammer for nested contents of list --- pom.xml | 2 +- .../io/github/gitbucket/markedj/Grammer.java | 3 ++- .../github/gitbucket/markedj/MarkedTest.java | 6 +++++ .../resources/nested_content_of_list.html | 25 +++++++++++++++++++ src/test/resources/nested_content_of_list.md | 24 ++++++++++++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/nested_content_of_list.html create mode 100644 src/test/resources/nested_content_of_list.md diff --git a/pom.xml b/pom.xml index 763dc88..3b96a52 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.gitbucket markedj jar - 1.0.7 + 1.0.8-SNAPSHOT markedj https://github.com/gitbucket/markedj JVM port of graceful markdown processor marked.js diff --git a/src/main/java/io/github/gitbucket/markedj/Grammer.java b/src/main/java/io/github/gitbucket/markedj/Grammer.java index 75a0166..37c8807 100644 --- a/src/main/java/io/github/gitbucket/markedj/Grammer.java +++ b/src/main/java/io/github/gitbucket/markedj/Grammer.java @@ -21,7 +21,8 @@ public class Grammer { public static String BLOCK_HEADING = "^ *(#{1,6}) *([^\\n]+?) *#* *(?:\\n+|$)"; public static String BLOCK_LHEADING = "^([^\\n]+)\\n *(=|-){2,} *(?:\\n+|$)"; public static String BLOCK_BLOCKQUOTE = "^( *>[^\\n]+(\\n(?!" + removeLineStart(DEF) + ")[^\\n]+)*\\n*)+"; - public static String BLOCK_LIST = "^( *)(" + BULLET + ") [\\s\\S]+?(?:" + HR + "|\\n+(?=" + removeLineStart(DEF) + ")|\\n{2,}(?! )(?!\\1" + BULLET + " )\\n*|\\s*$)"; + //public static String BLOCK_LIST = "^( *)(" + BULLET + ") [\\s\\S]+?(?:" + HR + "|\\n+(?=" + removeLineStart(DEF) + ")|\\n{2,}(?! )(?!\\1" + BULLET + " )\\n*|\\s*$)"; + public static String BLOCK_LIST = "^( *)(" + BULLET + ") [\\s\\S]+?(?:\\n{2,}(?! )(?!\\1" + BULLET + " )\\n*|\\s*$)"; public static String BLOCK_DEF = "^ *\\[([^\\]]+)\\]: *]+)>?(?: +[\"(]([^\\n]+)[\")])? *(?:\\n+|$)"; public static String BLOCK_PARAGRAPH = "^((?:[^\\n]+\\n?(?!" + removeLineStart(BLOCK_HR) + "|" + removeLineStart(BLOCK_HEADING) + "|" + removeLineStart(BLOCK_LHEADING) + "|" + removeLineStart(BLOCK_BLOCKQUOTE) + "|<" + TAG + "|" + removeLineStart(BLOCK_DEF) + "))+)\\n*"; public static String BLOCK_GFM_FENCES = "^ *(`{3,}|~{3,})[ \\.]*(\\S+)? *\\n([\\s\\S]*?)\\s*\\1 *(?:\\n+|$)"; diff --git a/src/test/java/io/github/gitbucket/markedj/MarkedTest.java b/src/test/java/io/github/gitbucket/markedj/MarkedTest.java index 1cff0c8..13342e7 100644 --- a/src/test/java/io/github/gitbucket/markedj/MarkedTest.java +++ b/src/test/java/io/github/gitbucket/markedj/MarkedTest.java @@ -137,6 +137,12 @@ public void testParagraphSeparation() throws Exception { "\n", result); } + @Test + public void testNestedContentOfList() throws Exception { + String result = Marked.marked(loadResourceAsString("nested_content_of_list.md"), new Options()); + assertEquals(loadResourceAsString("nested_content_of_list.html"), result); + } + private String loadResourceAsString(String path) throws IOException { InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); try { diff --git a/src/test/resources/nested_content_of_list.html b/src/test/resources/nested_content_of_list.html new file mode 100644 index 0000000..2e8203a --- /dev/null +++ b/src/test/resources/nested_content_of_list.html @@ -0,0 +1,25 @@ +
    +
  • 3.4 Use computed property names when creating objects with dynamic property names.
    +

    Why? They allow you to define all the properties of an object in one place.

    +
    +
    
    +function getKey(k) {
    +  return `a key named ${k}`;
    +}
    +
    +// bad
    +const obj = {
    +  id: 5,
    +  name: 'San Francisco',
    +};
    +obj[getKey('enabled')] = true;
    +
    +// good
    +const obj = {
    +  id: 5,
    +  name: 'San Francisco',
    +  [getKey('enabled')]: true,
    +};
    +
    +
  • +
diff --git a/src/test/resources/nested_content_of_list.md b/src/test/resources/nested_content_of_list.md new file mode 100644 index 0000000..61c83d0 --- /dev/null +++ b/src/test/resources/nested_content_of_list.md @@ -0,0 +1,24 @@ + - [3.4](#es6-computed-properties) Use computed property names when creating objects with dynamic property names. + + > Why? They allow you to define all the properties of an object in one place. + + ```javascript + + function getKey(k) { + return `a key named ${k}`; + } + + // bad + const obj = { + id: 5, + name: 'San Francisco', + }; + obj[getKey('enabled')] = true; + + // good + const obj = { + id: 5, + name: 'San Francisco', + [getKey('enabled')]: true, + }; + ``` \ No newline at end of file From 5748bd2deab1dca70fba344ca7d057226c99acdc Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 30 Apr 2016 10:15:15 +0900 Subject: [PATCH 04/10] Version 1.0.8 --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d8b789e..107f4cb 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ At first, add following dependency into your `pom.xml`: io.github.gitbucket markedj - 1.0.7 + 1.0.8 ``` diff --git a/pom.xml b/pom.xml index 3b96a52..b12e33a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.gitbucket markedj jar - 1.0.8-SNAPSHOT + 1.0.8 markedj https://github.com/gitbucket/markedj JVM port of graceful markdown processor marked.js From a702ebcdaead5cde2b2ee0e6d07675162b84e49c Mon Sep 17 00:00:00 2001 From: Matthieu Brouillard Date: Sat, 30 Apr 2016 10:37:47 +0200 Subject: [PATCH 05/10] add unit tests for quote/blockquote --- src/test/java/io/github/gitbucket/markedj/MarkedTest.java | 7 +++++++ src/test/resources/quote.html | 4 ++++ src/test/resources/quote.md | 2 ++ 3 files changed, 13 insertions(+) create mode 100644 src/test/resources/quote.html create mode 100644 src/test/resources/quote.md diff --git a/src/test/java/io/github/gitbucket/markedj/MarkedTest.java b/src/test/java/io/github/gitbucket/markedj/MarkedTest.java index 7c8e603..e39a212 100644 --- a/src/test/java/io/github/gitbucket/markedj/MarkedTest.java +++ b/src/test/java/io/github/gitbucket/markedj/MarkedTest.java @@ -12,6 +12,13 @@ * Created by takezoe on 15/09/19. */ public class MarkedTest { + @Test + public void testQuote() throws Exception { + String md = loadResourceAsString("quote.md"); + String result = Marked.marked(md, new Options()); + String expect = loadResourceAsString("quote.html"); + assertEquals(expect, result); + } @Test public void testMarked() throws Exception { diff --git a/src/test/resources/quote.html b/src/test/resources/quote.html new file mode 100644 index 0000000..0172764 --- /dev/null +++ b/src/test/resources/quote.html @@ -0,0 +1,4 @@ +
+

This is a quoting message +That spans over several lines

+
diff --git a/src/test/resources/quote.md b/src/test/resources/quote.md new file mode 100644 index 0000000..4983955 --- /dev/null +++ b/src/test/resources/quote.md @@ -0,0 +1,2 @@ +> This is a quoting message +> That spans over several lines \ No newline at end of file From 44b009df3ff688d989eb6bfeb95352830a3c441f Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Fri, 13 May 2016 00:12:27 -0400 Subject: [PATCH 06/10] (refs #14)Render empty table column --- .../io/github/gitbucket/markedj/Lexer.java | 80 ++++++++++++------- .../io/github/gitbucket/markedj/Parser.java | 12 +-- .../io/github/gitbucket/markedj/Utils.java | 17 ++++ .../github/gitbucket/markedj/MarkedTest.java | 33 ++++++++ src/test/resources/table.html | 1 + 5 files changed, 105 insertions(+), 38 deletions(-) diff --git a/src/main/java/io/github/gitbucket/markedj/Lexer.java b/src/main/java/io/github/gitbucket/markedj/Lexer.java index b72d9c5..48d1130 100644 --- a/src/main/java/io/github/gitbucket/markedj/Lexer.java +++ b/src/main/java/io/github/gitbucket/markedj/Lexer.java @@ -91,31 +91,43 @@ protected void token(String src, boolean top, boolean bq, LexerContext context){ if(!cap.isEmpty()){ src = src.substring(cap.get(0).length()); - String[] header = cap.get(1).replaceAll("^ *| *\\| *$", "").split(" *\\| *"); - String[] align = cap.get(2).replaceAll("^ *|\\| *$", "").split(" *\\| *"); - String[] cells = cap.get(3).replaceAll("\n$", "").split("\n"); + String[] headers = cap.get(1).replaceAll("^ *| *\\| *$", "").split(" *\\| *"); + String[] aligns = cap.get(2).replaceAll("^ *|\\| *$", "").split(" *\\| *"); + String[] rows = cap.get(3).replaceAll("\n$", "").split("\n"); - List header2 = Arrays.asList(header); + List headerList = array2list(headers); - List align2 = new ArrayList<>(); - for (String s : align) { + List alignList = new ArrayList<>(); + for (String s : aligns) { if(s.matches("^ *-+: *$")){ - align2.add("right"); + alignList.add("right"); } else if(s.matches("^ *:-+: *$")){ - align2.add("center"); + alignList.add("center"); } else if(s.matches("^ *:-+ *$")){ - align2.add("left"); + alignList.add("left"); } else { - align2.add(null); + alignList.add(null); } } - List> cells2 = new ArrayList<>(); - for (String cell : cells) { - cells2.add(Arrays.asList(cell.split(" *\\| *"))); + int maxColumns = Math.max(headers.length, aligns.length); + + List> rowList = new ArrayList<>(); + for (String row : rows) { + String[] columns = row.split(" *\\| *"); + if(maxColumns < columns.length){ + maxColumns = columns.length; + } + rowList.add(array2list(columns)); + } + + fillList(headerList, maxColumns, ""); + fillList(alignList, maxColumns, null); + for(List row: rowList){ + fillList(row, maxColumns, ""); } - context.pushToken(new TableToken(header2, align2, cells2)); + context.pushToken(new TableToken(headerList, alignList, rowList)); continue; } } @@ -255,31 +267,43 @@ protected void token(String src, boolean top, boolean bq, LexerContext context){ if(!cap.isEmpty()){ src = src.substring(cap.get(0).length()); - String[] header = cap.get(1).replaceAll("^ *| *\\| *$", "").split(" *\\| *"); - String[] align = cap.get(2).replaceAll("^ *|\\| *$", "").split(" *\\| *"); - String[] cells = cap.get(3).replaceAll("(?: *\\| *)?\\n$", "").split("\\n"); + String[] headers = cap.get(1).replaceAll("^ *| *\\| *$", "").split(" *\\| *"); + String[] aligns = cap.get(2).replaceAll("^ *|\\| *$", "").split(" *\\| *"); + String[] rows = cap.get(3).replaceAll("(?: *\\| *)?\\n$", "").split("\\n"); - List header2 = Arrays.asList(header); + List headerList = array2list(headers); - List align2 = new ArrayList<>(); - for (String s : align) { + List alignList = new ArrayList<>(); + for (String s : aligns) { if(s.matches("^ *-+: *$")){ - align2.add("right"); + alignList.add("right"); } else if(s.matches("^ *:-+: *$")){ - align2.add("center"); + alignList.add("center"); } else if(s.matches("^ *:-+ *$")){ - align2.add("left"); + alignList.add("left"); } else { - align2.add(null); + alignList.add(null); + } + } + + int maxColumns = Math.max(headers.length, aligns.length); + + List> rowList = new ArrayList<>(); + for (String row : rows) { + String[] columns = row.replaceAll("^ *\\| *| *\\| *$", "").split(" *\\| *"); + if(maxColumns < columns.length){ + maxColumns = columns.length; } + rowList.add(array2list(columns)); } - List> cells2 = new ArrayList<>(); - for (String cell : cells) { - cells2.add(Arrays.asList(cell.replaceAll("^ *\\| *| *\\| *$", "").split(" *\\| *"))); + fillList(headerList, maxColumns, ""); + fillList(alignList, maxColumns, null); + for(List row: rowList){ + fillList(row, maxColumns, ""); } - context.pushToken(new TableToken(header2, align2, cells2)); + context.pushToken(new TableToken(headerList, alignList, rowList)); continue; } } diff --git a/src/main/java/io/github/gitbucket/markedj/Parser.java b/src/main/java/io/github/gitbucket/markedj/Parser.java index b8f193b..8bda7c4 100644 --- a/src/main/java/io/github/gitbucket/markedj/Parser.java +++ b/src/main/java/io/github/gitbucket/markedj/Parser.java @@ -73,24 +73,16 @@ protected String tok(ParserContext context){ StringBuilder outBody = new StringBuilder(); for(int i = 0; i < t.getHeader().size(); i++){ - String align = null; - if(t.getAlign().size() > i){ - align = t.getAlign().get(i); - } outCell.append(renderer.tablecell( - context.getInlineLexer().output(t.getHeader().get(i)), new Renderer.TableCellFlags(true, align))); + context.getInlineLexer().output(t.getHeader().get(i)), new Renderer.TableCellFlags(true, t.getAlign().get(i)))); } outHeader.append(renderer.tablerow(outCell.toString())); for(int i = 0; i < t.getCells().size(); i++){ outCell.setLength(0); for(int j = 0; j < t.getCells().get(i).size(); j++){ - String align = null; - if(t.getAlign().size() > j){ - align = t.getAlign().get(j); - } outCell.append(renderer.tablecell( - context.getInlineLexer().output(t.getCells().get(i).get(j)), new Renderer.TableCellFlags(false, align))); + context.getInlineLexer().output(t.getCells().get(i).get(j)), new Renderer.TableCellFlags(false, t.getAlign().get(j)))); } outBody.append(renderer.tablerow(outCell.toString())); } diff --git a/src/main/java/io/github/gitbucket/markedj/Utils.java b/src/main/java/io/github/gitbucket/markedj/Utils.java index 1a41f6e..9bbc834 100644 --- a/src/main/java/io/github/gitbucket/markedj/Utils.java +++ b/src/main/java/io/github/gitbucket/markedj/Utils.java @@ -1,5 +1,8 @@ package io.github.gitbucket.markedj; +import java.util.ArrayList; +import java.util.List; + public class Utils { public static String escape(String html){ @@ -27,4 +30,18 @@ public static boolean isEmpty(String str){ return str == null || str.length() == 0; } + public static void fillList(List list, int length, String value){ + while(list.size() < length){ + list.add(value); + } + } + + public static List array2list(String[] array){ + List list = new ArrayList<>(array.length); + for(String value: array){ + list.add(value); + } + return list; + } + } diff --git a/src/test/java/io/github/gitbucket/markedj/MarkedTest.java b/src/test/java/io/github/gitbucket/markedj/MarkedTest.java index e39a212..800cfe2 100644 --- a/src/test/java/io/github/gitbucket/markedj/MarkedTest.java +++ b/src/test/java/io/github/gitbucket/markedj/MarkedTest.java @@ -156,6 +156,39 @@ public void testNestedContentOfList() throws Exception { assertEquals(loadResourceAsString("nested_content_of_list.html"), result); } + @Test + public void testEmptyTableCell() throws Exception { + String result = Marked.marked( + "|ID|name|note|\n" + + "|-|-|-|\n" + + "|1|foo|This is foo|\n" + + "|2|bar||"); + + + assertEquals( + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "
IDnamenote
1fooThis is foo
2bar
\n", result); + } + private String loadResourceAsString(String path) throws IOException { InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); try { diff --git a/src/test/resources/table.html b/src/test/resources/table.html index 6bcb032..f03cc6d 100644 --- a/src/test/resources/table.html +++ b/src/test/resources/table.html @@ -3,6 +3,7 @@ aa aa + From e739d7c335e32e5d3b15baf11307e93fcd3231b8 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Fri, 13 May 2016 00:16:42 -0400 Subject: [PATCH 07/10] Update version with 1.0.9-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b12e33a..5d1fde1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.gitbucket markedj jar - 1.0.8 + 1.0.9-SNAPSHOT markedj https://github.com/gitbucket/markedj JVM port of graceful markdown processor marked.js From be2e7343bd24266b09df5e42608ca7da4b2daa96 Mon Sep 17 00:00:00 2001 From: koda Date: Wed, 18 May 2016 22:03:57 +0900 Subject: [PATCH 08/10] add static import for utils --- src/main/java/io/github/gitbucket/markedj/Lexer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/github/gitbucket/markedj/Lexer.java b/src/main/java/io/github/gitbucket/markedj/Lexer.java index e4ed7ad..f8c8d13 100644 --- a/src/main/java/io/github/gitbucket/markedj/Lexer.java +++ b/src/main/java/io/github/gitbucket/markedj/Lexer.java @@ -5,6 +5,8 @@ import java.util.*; +import static io.github.gitbucket.markedj.Utils.*; + public class Lexer { protected Options options; From eef899b395386f636b5f310cb12c235cc9a5fdba Mon Sep 17 00:00:00 2001 From: koda Date: Thu, 19 May 2016 04:19:52 +0900 Subject: [PATCH 09/10] Generate the sequential ID for table of contents --- .../io/github/gitbucket/markedj/Marked.java | 3 + .../io/github/gitbucket/markedj/Options.java | 27 ++++++ .../io/github/gitbucket/markedj/Renderer.java | 4 + .../gitbucket/markedj/ExtendParseTest.java | 93 +++++++++++++------ src/test/resources/debug.md | 29 ++++++ src/test/resources/header_id.html | 38 ++++++++ src/test/resources/header_id.md | 29 ++++++ 7 files changed, 195 insertions(+), 28 deletions(-) create mode 100644 src/test/resources/debug.md create mode 100644 src/test/resources/header_id.html create mode 100644 src/test/resources/header_id.md diff --git a/src/main/java/io/github/gitbucket/markedj/Marked.java b/src/main/java/io/github/gitbucket/markedj/Marked.java index d77d16d..bf166f2 100644 --- a/src/main/java/io/github/gitbucket/markedj/Marked.java +++ b/src/main/java/io/github/gitbucket/markedj/Marked.java @@ -8,6 +8,9 @@ public static String marked(String src) { } public static String marked(String src, Options options) { + if (options.isHeaderIdSequential()) { + options.initSequentialId(); + } return marked(src, options, new Renderer(options)); } diff --git a/src/main/java/io/github/gitbucket/markedj/Options.java b/src/main/java/io/github/gitbucket/markedj/Options.java index 22b35a8..6e91ab9 100644 --- a/src/main/java/io/github/gitbucket/markedj/Options.java +++ b/src/main/java/io/github/gitbucket/markedj/Options.java @@ -15,9 +15,20 @@ public class Options { private String langPrefix = "lang-"; // private boolean smartypants = false; private String headerPrefix = ""; + private boolean headerIdSequential; private boolean xhtml = false; private boolean linkTargetBlank; + private int sequentialId = 0; + public void initSequentialId() { + sequentialId = 0; + } + public int SequentialId() { + sequentialId++; + return sequentialId; + } + + public void setGfm(boolean gfm) { this.gfm = gfm; } @@ -127,4 +138,20 @@ public boolean isLinkTargetBlank() { public void setLinkTargetBlank(boolean linkTargetBlank) { this.linkTargetBlank = linkTargetBlank; } + + /** + * Get headerIdSequential + * @return the headerIdSequential + */ + public boolean isHeaderIdSequential() { + return headerIdSequential; + } + + /** + * Set headerIdSequential + * @param headerIdSequential the headerIdSequential to set + */ + public void setHeaderIdSequential(boolean headerIdSequential) { + this.headerIdSequential = headerIdSequential; + } } diff --git a/src/main/java/io/github/gitbucket/markedj/Renderer.java b/src/main/java/io/github/gitbucket/markedj/Renderer.java index bc0f013..d8bae14 100644 --- a/src/main/java/io/github/gitbucket/markedj/Renderer.java +++ b/src/main/java/io/github/gitbucket/markedj/Renderer.java @@ -45,6 +45,10 @@ public String html(String html){ } public String heading(String text, int level, String raw){ + if (options.isHeaderIdSequential()) { + return "" + text + "\n"; + } return "" + text + "\n"; } diff --git a/src/test/java/io/github/gitbucket/markedj/ExtendParseTest.java b/src/test/java/io/github/gitbucket/markedj/ExtendParseTest.java index eb71b9b..73abda5 100644 --- a/src/test/java/io/github/gitbucket/markedj/ExtendParseTest.java +++ b/src/test/java/io/github/gitbucket/markedj/ExtendParseTest.java @@ -9,34 +9,71 @@ import org.junit.Test; public class ExtendParseTest { + + public static void main(String[] args) throws IOException { + ExtendParseTest test = new ExtendParseTest(); + test.debug(); + } + + private void debug() throws IOException { + Options options = new Options(); + options.setBreaks(true); + options.setLinkTargetBlank(true); + options.setHeaderPrefix("markdown-agenda-"); + options.setHeaderIdSequential(true); - @Test - public void testLinkTarget() throws Exception { - Options options = new Options(); - options.setBreaks(true); - options.setLinkTargetBlank(true); - - String md = loadResourceAsString("link_target.md"); - String result = Marked.marked(md, options); - System.out.println(result); - String expect = loadResourceAsString("link_target.html"); - System.out.println(expect); - assertEquals(expect, result); - } - - private String loadResourceAsString(String path) throws IOException { - InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); - try { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - byte[] buf = new byte[1024 * 8]; - int length = 0; - while ((length = in.read(buf)) != -1) { - out.write(buf, 0, length); - } - return new String(out.toByteArray(), "UTF-8"); - } finally { - in.close(); - } - } + String md = loadResourceAsString("debug.md"); + String result = Marked.marked(md, options); + System.out.println(result); + } + + @Test + public void testHeaderId() throws Exception { + Options options = new Options(); + options.setBreaks(true); + options.setLinkTargetBlank(true); + options.setHeaderPrefix("markdown-agenda-"); + options.setHeaderIdSequential(true); + + String md = loadResourceAsString("header_id.md"); + String result = Marked.marked(md, options); + System.out.println(result); + String expect = loadResourceAsString("header_id.html"); + System.out.println(expect); + assertEquals(expect, result); + } + + + + + + @Test + public void testLinkTarget() throws Exception { + Options options = new Options(); + options.setBreaks(true); + options.setLinkTargetBlank(true); + + String md = loadResourceAsString("link_target.md"); + String result = Marked.marked(md, options); +// System.out.println(result); + String expect = loadResourceAsString("link_target.html"); +// System.out.println(expect); + assertEquals(expect, result); + } + + private String loadResourceAsString(String path) throws IOException { + InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); + try { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buf = new byte[1024 * 8]; + int length = 0; + while ((length = in.read(buf)) != -1) { + out.write(buf, 0, length); + } + return new String(out.toByteArray(), "UTF-8"); + } finally { + in.close(); + } + } } diff --git a/src/test/resources/debug.md b/src/test/resources/debug.md new file mode 100644 index 0000000..7915cf2 --- /dev/null +++ b/src/test/resources/debug.md @@ -0,0 +1,29 @@ +# hoge + +- aaa bbb ccc + +## fuga -1 + +- aaaaaaaaaa +- bbbbbbbbbb + +## fuga -2 + +- ああああああ +- いいいいいい + +## ふがー③ + +### 三段目の1 + +- @@@@@@ + +### 三段目の2 + +| aaa | bbb | ccc| +|-----|-----|----| +| ① | ② | ③ | + +# テスト + +## テスト2 diff --git a/src/test/resources/header_id.html b/src/test/resources/header_id.html new file mode 100644 index 0000000..445c1f1 --- /dev/null +++ b/src/test/resources/header_id.html @@ -0,0 +1,38 @@ +

hoge

+
    +
  • aaa bbb ccc
  • +
+

fuga -1

+
    +
  • aaaaaaaaaa
  • +
  • bbbbbbbbbb
  • +
+

fuga -2

+
    +
  • ああああああ
  • +
  • いいいいいい
  • +
+

ふがー③

+

三段目の1

+
    +
  • @@@@@@
  • +
+

三段目の2

+ + + + + + + + + + + + + + + +
aaabbbccc
+

テスト

+

テスト2

diff --git a/src/test/resources/header_id.md b/src/test/resources/header_id.md new file mode 100644 index 0000000..7915cf2 --- /dev/null +++ b/src/test/resources/header_id.md @@ -0,0 +1,29 @@ +# hoge + +- aaa bbb ccc + +## fuga -1 + +- aaaaaaaaaa +- bbbbbbbbbb + +## fuga -2 + +- ああああああ +- いいいいいい + +## ふがー③ + +### 三段目の1 + +- @@@@@@ + +### 三段目の2 + +| aaa | bbb | ccc| +|-----|-----|----| +| ① | ② | ③ | + +# テスト + +## テスト2 From 84a09b22f2d41330b571bbd62731fedc26cea6dc Mon Sep 17 00:00:00 2001 From: koda Date: Tue, 24 May 2016 00:25:57 +0900 Subject: [PATCH 10/10] Release v1.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a2bf834..b54c76c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.support-project markedj jar - 1.4.0-SNAPSHOT + 1.4.0 markedj https://github.com/gitbucket/markedj Fork from gitbucket markedj because knowledge's issue. markedj is JVM port of graceful markdown processor marked.js