├── src ├── test │ ├── resources │ │ ├── conversions │ │ │ ├── markdown │ │ │ │ ├── tables-remove.md │ │ │ │ ├── abbr.md │ │ │ │ ├── inlinestyle-emptybreak.md │ │ │ │ ├── unknownHTML.md │ │ │ │ ├── horizontalrule.md │ │ │ │ ├── abbr-enabled.md │ │ │ │ ├── unknownHTML-allowed.md │ │ │ │ ├── broken.md │ │ │ │ ├── paragraph.md │ │ │ │ ├── inlinecode.md │ │ │ │ ├── blockquote.md │ │ │ │ ├── header.md │ │ │ │ ├── break-hardwrap.md │ │ │ │ ├── break.md │ │ │ │ ├── header-headerids.md │ │ │ │ ├── inlinestyle-inword-removed.md │ │ │ │ ├── inlinestyle.md │ │ │ │ ├── inlinestyle-inword-spaced.md │ │ │ │ ├── codeblock.md │ │ │ │ ├── definitions-enabled.md │ │ │ │ ├── tables-multimarkdown.md │ │ │ │ ├── definitions.md │ │ │ │ ├── tables-markdownextra.md │ │ │ │ ├── anchor-simpleids.md │ │ │ │ ├── anchor-inline.md │ │ │ │ ├── anchor-relative.md │ │ │ │ ├── tables-codeblock.md │ │ │ │ ├── anchor-autolink.md │ │ │ │ ├── codeblock-fenced-backtick.md │ │ │ │ ├── codeblock-fenced-tilde.md │ │ │ │ ├── listordered.md │ │ │ │ ├── listunordered.md │ │ │ │ ├── anchor.md │ │ │ │ ├── image.md │ │ │ │ └── tables.md │ │ │ └── html │ │ │ │ ├── horizontalrule.html │ │ │ │ ├── inlinestyle-emptybreak.html │ │ │ │ ├── unknownHTML.html │ │ │ │ ├── abbr.html │ │ │ │ ├── break.html │ │ │ │ ├── paragraph.html │ │ │ │ ├── inlinecode.html │ │ │ │ ├── blockquote.html │ │ │ │ ├── header.html │ │ │ │ ├── broken.html │ │ │ │ ├── image.html │ │ │ │ ├── codeblock.html │ │ │ │ ├── anchor.html │ │ │ │ ├── definitions.html │ │ │ │ ├── listordered.html │ │ │ │ ├── listunordered.html │ │ │ │ ├── inlinestyle.html │ │ │ │ └── tables.html │ │ ├── textcleaner │ │ │ ├── cleanCodeBasic.out.txt │ │ │ ├── cleanBasic.out.txt │ │ │ ├── basic.in.txt │ │ │ ├── cleanCodeFull.out.txt │ │ │ ├── cleanFull.out.txt │ │ │ └── full.in.txt │ │ └── util │ │ │ ├── MarkdownTableTest.md │ │ │ ├── MarkdownTableColspanTest.md │ │ │ ├── MarkdownTableAsCodeTest.md │ │ │ ├── MarkdownTableAlignmentTest.md │ │ │ └── MarkdownTableWideColspanTest.md │ └── java │ │ └── com │ │ └── overzealous │ │ └── remark │ │ ├── convert │ │ ├── BrokenHTMLTest.java │ │ ├── AnchorInlineTest.java │ │ ├── AnchorSimpleIdTest.java │ │ ├── TableRemoveTest.java │ │ ├── AnchorRelativeLinkTest.java │ │ ├── InwordEmphasisSpacedTest.java │ │ ├── IgnoredHTMLTest.java │ │ ├── PlainMarkdownTest.java │ │ ├── MultiMarkdownTest.java │ │ ├── GithubTest.java │ │ ├── MarkdownExtraTest.java │ │ ├── PegdownTest.java │ │ ├── RemarkTester.java │ │ ├── DocumentConverterTest.java │ │ └── TextCleanerTest.java │ │ └── util │ │ ├── TestUtils.java │ │ ├── StringUtilsTest.java │ │ ├── BlockWriterTest.java │ │ └── MarkdownTableTest.java ├── manual │ ├── favicon.ico │ ├── images │ │ ├── icon128.png │ │ ├── icon16.png │ │ ├── icon32.png │ │ ├── top-header.png │ │ ├── header-marker.png │ │ └── selected-tab.png │ ├── apple-touch-icon.png │ ├── apple-touch-icon-precomposed.png │ ├── apple-touch-icon-57x57-precomposed.png │ ├── apple-touch-icon-72x72-precomposed.png │ ├── apple-touch-icon-114x114-precomposed.png │ ├── .htaccess │ ├── js │ │ └── libs │ │ │ └── prettify │ │ │ └── prettify.css │ ├── license.md │ ├── _template.html │ ├── index.md │ ├── usage.md │ ├── examples.md │ └── css │ │ ├── style.css │ │ └── normalize.css └── main │ └── java │ └── com │ └── overzealous │ └── remark │ ├── util │ ├── package-info.java │ ├── MarkdownTableCell.java │ ├── StringUtils.java │ └── MarkdownTable.java │ ├── convert │ ├── package-info.java │ ├── HorizontalRule.java │ ├── InlineCode.java │ ├── BlockQuote.java │ ├── Paragraph.java │ ├── Abbr.java │ ├── Break.java │ ├── NodeRemover.java │ ├── DefaultNodeHandler.java │ ├── Header.java │ ├── NodeHandler.java │ ├── Image.java │ ├── List.java │ ├── Codeblock.java │ ├── Anchor.java │ ├── AbstractNodeHandler.java │ ├── Definitions.java │ └── Table.java │ ├── package-info.java │ ├── IgnoredHtmlElement.java │ └── Main.java ├── .travis.yml ├── LICENSE ├── .gitignore ├── pom.xml └── README.markdown /src/test/resources/conversions/markdown/tables-remove.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/resources/conversions/markdown/abbr.md: -------------------------------------------------------------------------------- 1 | before HTML after 2 | 3 | before HTML after -------------------------------------------------------------------------------- /src/test/resources/conversions/markdown/inlinestyle-emptybreak.md: -------------------------------------------------------------------------------- 1 | *Empty Break Test* 2 | -------------------------------------------------------------------------------- /src/manual/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giflw/remark-java/HEAD/src/manual/favicon.ico -------------------------------------------------------------------------------- /src/test/resources/conversions/markdown/unknownHTML.md: -------------------------------------------------------------------------------- 1 | Division 2 | 3 | Foo Bar 4 | 5 | *Variable* -------------------------------------------------------------------------------- /src/test/resources/conversions/html/horizontalrule.html: -------------------------------------------------------------------------------- 1 |
Some text
2 |Some more text
-------------------------------------------------------------------------------- /src/test/resources/conversions/html/inlinestyle-emptybreak.html: -------------------------------------------------------------------------------- 1 |Empty Break Test
Variable
-------------------------------------------------------------------------------- /src/test/resources/conversions/html/abbr.html: -------------------------------------------------------------------------------- 1 |before HTML after
2 |before HTML after
-------------------------------------------------------------------------------- /src/test/resources/util/MarkdownTableAlignmentTest.md: -------------------------------------------------------------------------------- 1 | 2 | | h1 | h2 | h3 | 3 | |:-------- |:--------:| --------:| 4 | | col1 | col2 | col3 | 5 | | column 1 | column 2 | column 3 | -------------------------------------------------------------------------------- /src/test/resources/conversions/html/break.html: -------------------------------------------------------------------------------- 1 | Testing non-para breaksTesting paragraph break
broken!
This is a paragraph
2 | 3 | This is an auto-paragraph 4 | 5 |Whitespace test
line two
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |line three
-------------------------------------------------------------------------------- /src/test/resources/textcleaner/full.in.txt: -------------------------------------------------------------------------------- 1 | + leading plus 2 | *em* **strong** 3 | < > " & < '©' 4 | “ ” ‘ ’ ' « » “ ” ‘ ’ « » 5 | – — … – — … 6 | ` * _ { } [ ] # | -------------------------------------------------------------------------------- /src/test/resources/conversions/html/inlinecode.html: -------------------------------------------------------------------------------- 1 |Code: <tag> ![]
Special Code: <tag> ``
More Special Code: `
Code with a BR: Two
Lines
2 | This is quoted text. 3 |7 | 8 |4 | This is also quoted text. 5 |6 |
Quoted Text12 |
content
3 |content
5 |content
7 |content
9 |
2 |
3 |
4 | This is really bad HTML
5 |
6 | I'm deeply nested Basic: Title not alt: Duplicate: No alternate: No valid alternate: No alternate, no name: Before after after 2 Test duplicate URLs: Full Path Link 2 Autolink: http://www.google.com/ Term First: Definition first: Multiple definitions: Simple Nested Inner Block Content Paragraph 1 Paragraph 2 Simple Nested Inner Block Content Paragraph 1 Paragraph 2 italics bold italics old bold old spanned italics spanned bold spanned both nested Empty, leading, inline and trailing spaces. InWordStyle - InWordStyle - InWordStyle Contains strike through text
--------------------------------------------------------------------------------
/src/test/resources/conversions/html/tables.html:
--------------------------------------------------------------------------------
1 | For more information, see the BitBucket Repository. For more information, see the BitBucket Repository. This library is used to processConvert HTML files back into valid Markdown code. To get started, check out the {@link com.overzealous.remark.Remark} class. For more information, see the BitBucket Repository. Hello World
113 |
114 |
115 | This is really bad HTML
116 |
117 | I'm deeply nested This is HTML! This link will render completely inline: http://www.example.com These fancy characters will be reverted to simple UTF-8 or simple quotes: “This — that…”



4 |
5 | Code
3 | Block
6 | Unsafe <Characters>
7 | thing[0];
8 | -> ^_^ <-
9 |
10 |
11 |
19 |
20 | This is a paragraph introducing:
14 |
15 | ~~~~
16 | a one-line code block
17 | ~~~~
18 | This pre has
--------------------------------------------------------------------------------
/src/test/resources/conversions/markdown/tables-codeblock.md:
--------------------------------------------------------------------------------
1 | | --- |
2 | | One |
3 |
4 | | --- | --- |
5 | | One | Two |
6 |
7 | | ----- |
8 | | One |
9 | | -Two- |
10 |
11 | | head 1 | head 2 |
12 | | ------ | ------ |
13 | | one | two |
14 |
15 | | head 1 | head 2 |
16 | |:------:| ------:|
17 | | one | two |
18 |
19 | | head 1 | head 2 ||
20 | |:------:| ---:|:----- |
21 | | one | two | three |
--------------------------------------------------------------------------------
/src/test/resources/conversions/markdown/anchor-autolink.md:
--------------------------------------------------------------------------------
1 | Empty Link:
2 |
3 | Ignored Link
4 |
5 | [Hash Link][]
6 |
7 | [Relative Path Link][]
8 |
9 | [Full Path Link][]
10 |
11 | Test duplicate URLs: [Full Path Link 2][Full Path Link]
12 |
13 | Autolink: http://www.google.com/
14 |
15 | [***Over-Styled Link***][Full Path Link]
16 |
17 |
18 | [Hash Link]: http://www.example.com/#hash
19 | [Relative Path Link]: http://www.example.com/rel/path
20 | [Full Path Link]: http://www.google.com/
--------------------------------------------------------------------------------
/src/test/resources/conversions/markdown/codeblock-fenced-backtick.md:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | ``````````
4 | Code
5 | Block
6 | ``````````
7 |
8 | ``````````
9 | Unsafe
line break tags
23 | another one
end
3 |
8 |
9 |
11 |
15 |
16 |
18 |
--------------------------------------------------------------------------------
/src/test/resources/conversions/markdown/image.md:
--------------------------------------------------------------------------------
1 | Basic: ![Example Image][]
2 |
3 | Title not alt: ![Example Image 2][]
4 |
5 | Duplicate: ![Example Image 3][Example Image]
6 |
7 | No alternate: ![example3.jpg][]
8 |
9 | No valid alternate: ![%$^$][Image 1]
10 |
11 | No alternate, no name: ![Image 2][]
12 |
13 |
14 | [Example Image]: http://www.example.com/example.jpg
15 | [Example Image 2]: http://www.example.com/example2.jpg
16 | [example3.jpg]: http://www.example.com/example3.jpg
17 | [Image 1]: http://www.example.com/foo/
18 | [Image 2]: http://www.example.com/blah/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2011 OverZealous Creations, LLC
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
--------------------------------------------------------------------------------
/src/manual/js/libs/prettify/prettify.css:
--------------------------------------------------------------------------------
1 | .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
--------------------------------------------------------------------------------
/src/test/resources/conversions/html/listordered.html:
--------------------------------------------------------------------------------
1 |
3 |
7 |
9 |
33 |
12 |
16 |
21 |
31 |
25 |
28 |
35 |
--------------------------------------------------------------------------------
/src/test/resources/conversions/html/listunordered.html:
--------------------------------------------------------------------------------
1 | Quoted
41 |
3 |
7 |
9 |
33 |
12 |
16 |
21 |
31 |
25 |
28 |
35 |
--------------------------------------------------------------------------------
/src/test/resources/conversions/html/inlinestyle.html:
--------------------------------------------------------------------------------
1 | Quoted
41 |
2 |
3 | One
4 |
5 | One Two
6 |
13 |
14 |
7 |
9 | One
8 |
10 |
12 | -Two-
11 |
15 |
18 |
19 |
16 | head 1 head 2
17 | one two
20 |
23 |
24 |
21 | head 1 head 2
22 | one two
25 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/util/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * This package contains utility classes that assist the main parser in rendering Markdown output.
19 | *
20 | *
26 | head 1 head 2
27 | one two three
2 |
3 |
8 |
9 |
4 |
6 |
7 | One
5 |
10 |
11 |
17 |
18 |
12 |
15 |
16 | One
13 | Two
14 |
19 |
20 |
28 |
29 |
21 |
23 | One
22 |
24 |
26 |
27 | -Two-
25 |
30 |
31 |
43 |
44 |
32 |
35 |
36 |
37 | head 1
33 | head 2
34 |
38 |
41 |
42 | one
39 | two
40 |
45 |
46 |
58 |
59 |
47 |
50 |
51 |
52 | head 1
48 | head 2
49 |
53 |
56 |
57 | one
54 | two
55 |
60 |
61 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/HorizontalRule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.util.StringUtils;
20 | import org.jsoup.nodes.Element;
21 |
22 | /**
23 | * Handles a simple hr tag
24 | *
25 | * @author Phil DeJarnett
26 | */
27 | public class HorizontalRule extends AbstractNodeHandler {
28 |
29 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
30 | converter.output.startBlock();
31 | StringUtils.multiply(converter.output, '-', 20);
32 | converter.output.endBlock();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/AnchorInlineTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.Options;
20 | import com.overzealous.remark.Remark;
21 | import org.junit.Test;
22 |
23 | /**
24 | * @author Phil DeJarnett
25 | */
26 | public class AnchorInlineTest extends RemarkTester {
27 |
28 | @Override
29 | public Remark setupRemark() {
30 | Options opts = Options.markdown();
31 | opts.inlineLinks = true;
32 | return new Remark(opts);
33 | }
34 |
35 | @Test public void testAnchors() throws Exception { test("anchor", "inline"); }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/AnchorSimpleIdTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.Options;
20 | import com.overzealous.remark.Remark;
21 | import org.junit.Test;
22 |
23 | /**
24 | * @author Phil DeJarnett
25 | */
26 | public class AnchorSimpleIdTest extends RemarkTester {
27 |
28 | @Override
29 | public Remark setupRemark() {
30 | Options opts = Options.markdown();
31 | opts.simpleLinkIds = true;
32 | return new Remark(opts);
33 | }
34 |
35 | @Test public void testAnchors() throws Exception { test("anchor", "simpleids"); }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/TableRemoveTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.Options;
20 | import com.overzealous.remark.Remark;
21 | import org.junit.Test;
22 |
23 | /**
24 | * @author Phil DeJarnett
25 | */
26 | public class TableRemoveTest extends RemarkTester {
27 |
28 | @Override
29 | public Remark setupRemark() {
30 | Options opts = Options.markdown();
31 | opts.tables = Options.Tables.REMOVE;
32 | return new Remark(opts);
33 | }
34 |
35 | @Test public void testTables() throws Exception { test("tables", "remove"); }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/AnchorRelativeLinkTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.Options;
20 | import com.overzealous.remark.Remark;
21 | import org.junit.Test;
22 |
23 | /**
24 | * @author Phil DeJarnett
25 | */
26 | public class AnchorRelativeLinkTest extends RemarkTester {
27 |
28 | @Override
29 | public Remark setupRemark() {
30 | Options opts = Options.markdown();
31 | opts.preserveRelativeLinks = true;
32 | return new Remark(opts);
33 | }
34 |
35 | @Test public void testAnchors() throws Exception { test("anchor", "relative"); }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/InwordEmphasisSpacedTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.Options;
20 | import com.overzealous.remark.Remark;
21 | import org.junit.Test;
22 |
23 | /**
24 | * @author Phil DeJarnett
25 | */
26 | public class InwordEmphasisSpacedTest extends RemarkTester {
27 |
28 | @Override
29 | public Remark setupRemark() {
30 | Options opts = Options.markdown();
31 | opts.inWordEmphasis = Options.InWordEmphasis.ADD_SPACES;
32 | return new Remark(opts);
33 | }
34 |
35 | @Test public void testInlineStyle() throws Exception { test("inlinestyle", "inword-spaced"); }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/InlineCode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import org.jsoup.nodes.Element;
20 |
21 | /**
22 | * Handles inline fixed-width code (code, tt) tags.
23 | * @author Phil DeJarnett
24 | */
25 | public class InlineCode extends AbstractNodeHandler {
26 |
27 | /**
28 | * Renders inline-styled code.
29 | *
30 | * @param parent The previous node walker, in case we just want to remove an element.
31 | * @param node Node to handle
32 | * @param converter Parent converter for this object.
33 | */
34 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
35 | converter.output.write(converter.cleaner.cleanInlineCode(node));
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/manual/license.md:
--------------------------------------------------------------------------------
1 | # License
2 |
3 | **Remark** is released under the [Apache 2.0 license][].
4 |
5 | Copyright 2011 OverZealous Creations, LLC
6 |
7 | Licensed under the Apache License, Version 2.0 (the "License");
8 | you may not use this file except in compliance with the License.
9 | You may obtain a copy of the License at
10 |
11 | http://www.apache.org/licenses/LICENSE-2.0
12 |
13 | Unless required by applicable law or agreed to in writing, software
14 | distributed under the License is distributed on an "AS IS" BASIS,
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | See the License for the specific language governing permissions and
17 | limitations under the License.
18 |
19 | Feel free to copy and share this library in your personal and commercial projects.
20 |
21 | ## Dependent Licenses
22 |
23 | **Remark** depends on [jsoup][] and [Apache Commons Lang 3][]. If you want to use it from the command line, it also depends on [Apache Commons CLI][].
24 |
25 | jsoup uses the [MIT License][jsoup license], which is roughly comparable to the [Apache 2.0 License][] used by Remark and the Apache dependencies.
26 |
27 |
28 | [jsoup]: http://jsoup.org/
29 | [jsoup license]: http://jsoup.org/license
30 | [Apache Commons Lang 3]: http://commons.apache.org/lang/
31 | [Apache Commons CLI]: http://commons.apache.org/cli/
32 | [Apache 2.0 License]: http://www.apache.org/licenses/LICENSE-2.0
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/IgnoredHTMLTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.IgnoredHtmlElement;
20 | import com.overzealous.remark.Options;
21 | import com.overzealous.remark.Remark;
22 | import org.junit.Test;
23 |
24 | /**
25 | * @author Phil DeJarnett
26 | */
27 | public class IgnoredHTMLTest extends RemarkTester {
28 |
29 | @Override
30 | public Remark setupRemark() {
31 | Options opts = Options.markdown();
32 | opts.getIgnoredHtmlElements().add(IgnoredHtmlElement.create("var"));
33 | opts.getIgnoredHtmlElements().add(IgnoredHtmlElement.create("foo-bar", "class"));
34 | return new Remark(opts);
35 | }
36 |
37 | @Test public void testUnknownHTML() throws Exception { test("unknownHTML", "allowed"); }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/BlockQuote.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import org.jsoup.nodes.Element;
20 |
21 | /**
22 | * Handles blockquote tags
23 | * @author Phil DeJarnett
24 | */
25 | public class BlockQuote extends AbstractNodeHandler {
26 |
27 | /**
28 | * Processes a quoted section.
29 | *
30 | * @param parent The previous node walker, in case we just want to remove an element.
31 | * @param node Node to handle
32 | * @param converter Parent converter for this object.
33 | */
34 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
35 | // handle block quotes
36 | converter.output.startBlock();
37 | prependAndRecurse("> ", node, converter, converter.blockNodes);
38 | converter.output.endBlock();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/Paragraph.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import org.jsoup.nodes.Element;
20 |
21 | /**
22 | * Handles paragraph (p) tags.
23 | * @author Phil DeJarnett
24 | */
25 | public class Paragraph extends AbstractNodeHandler {
26 |
27 | /**
28 | * Creates a standard text block, then walks down over inline nodes.
29 | *
30 | * @param parent The previous node walker, in case we just want to remove an element.
31 | * @param node Node to handle
32 | * @param converter Parent converter for this object.
33 | */
34 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
35 | converter.output.startBlock();
36 | converter.walkNodes(this, node, converter.inlineNodes);
37 | converter.output.endBlock();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/Abbr.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import org.jsoup.nodes.Element;
20 |
21 | /**
22 | * Handles abbr and acronym tags
23 | * @author Phil DeJarnett
24 | */
25 | public class Abbr extends AbstractNodeHandler {
26 |
27 | /**
28 | * Handles abbreviations.
29 | *
30 | * @param parent The previous node walker, in case we just want to remove an element.
31 | * @param node Node to handle
32 | * @param converter Parent converter for this object.
33 | */
34 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
35 | String abbr = converter.cleaner.clean(node);
36 | if(abbr.length() > 0) {
37 | converter.output.print(abbr);
38 | String desc = node.attr("title");
39 | if(desc.length() > 0) {
40 | converter.addAbbreviation(abbr, desc);
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/Break.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import org.jsoup.nodes.Element;
20 |
21 | /**
22 | * Handles manual breaks (br)
23 | * @author Phil DeJarnett
24 | */
25 | public class Break extends AbstractNodeHandler {
26 |
27 | /**
28 | * Renders out forced linebreaks. If hardwraps are enabled, then this
29 | * simply prints a newline. Otherwise, it prints two spaces and a newline.
30 | *
31 | * @param parent The previous node walker, in case we just want to remove an element.
32 | * @param node Node to handle
33 | * @param converter Parent converter for this object.
34 | */
35 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
36 | if(!converter.options.hardwraps) {
37 | converter.output.println(" ");
38 | } else {
39 | converter.output.println();
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/NodeRemover.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import org.jsoup.nodes.Element;
20 | import org.jsoup.nodes.TextNode;
21 |
22 | /**
23 | * @author Phil DeJarnett
24 | */
25 | public class NodeRemover implements NodeHandler {
26 |
27 | private static NodeRemover instance;
28 |
29 | private NodeRemover() {
30 | // singleton
31 | }
32 |
33 | public static NodeRemover getInstance() {
34 | if(instance == null) {
35 | instance = new NodeRemover();
36 | }
37 | return instance;
38 | }
39 |
40 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
41 | // do nothing, node is removed.
42 | }
43 |
44 | public void handleTextNode(TextNode node, DocumentConverter converter) {
45 | // do nothing, node is removed.
46 | }
47 |
48 | public void handleIgnoredHTMLElement(Element node, DocumentConverter converter) {
49 | // do nothing, node is removed.
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/DefaultNodeHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import org.jsoup.nodes.Element;
20 |
21 | /**
22 | * Default handler for unknown top-level nodes.
23 | * @author Phil DeJarnett
24 | */
25 | public class DefaultNodeHandler extends AbstractNodeHandler {
26 |
27 | private static DefaultNodeHandler instance;
28 |
29 | public static DefaultNodeHandler getInstance() {
30 | if(instance == null) {
31 | instance = new DefaultNodeHandler();
32 | }
33 | return instance;
34 | }
35 |
36 | protected DefaultNodeHandler() {
37 | // exists for Singleton pattern
38 | }
39 |
40 | /**
41 | * For the default state element, the nodes are simply ignored, recursing as necessary.
42 | *
43 | * @param parent The previous node walker, in case we just want to remove an element.
44 | * @param node Node to handle
45 | * @param converter Parent converter for this object.
46 | */
47 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
48 | converter.walkNodes(this, node, converter.blockNodes);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/util/TestUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.util;
18 |
19 | import org.apache.commons.io.FileUtils;
20 |
21 | import java.io.File;
22 | import java.net.URL;
23 |
24 | /**
25 | * @author Phil DeJarnett
26 | */
27 | public class TestUtils {
28 |
29 | /**
30 | * Reads a resource into a string.
31 | * @param path Path to resource
32 | * @return String contents of resource
33 | */
34 | public static String readResourceToString(String path) {
35 | String result;
36 | try {
37 | URL u = StringUtils.class.getResource(path);
38 | if(u == null) {
39 | throw new Exception("Resource not found");
40 | }
41 | File f = FileUtils.toFile(u);
42 | if(!f.isFile()) {
43 | throw new Exception("Resource file does not exist or is not a file.");
44 | }
45 | result = FileUtils.readFileToString(f, "UTF-8");
46 | if(result == null) {
47 | throw new Exception("Error reading resource file.");
48 | }
49 | } catch(Exception e) {
50 | e.printStackTrace();
51 | result = "UNABLE TO LOAD RESOURCE "+path+": "+e.getMessage();
52 | }
53 | return result;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by https://www.gitignore.io
2 |
3 | ### Gradle ###
4 | .gradle
5 | build/
6 |
7 | # Ignore Gradle GUI config
8 | gradle-app.setting
9 |
10 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
11 | !gradle-wrapper.jar
12 |
13 | # Created by https://www.gitignore.io
14 |
15 | ### Maven ###
16 | target/
17 | pom.xml.tag
18 | pom.xml.releaseBackup
19 | pom.xml.versionsBackup
20 | pom.xml.next
21 | release.properties
22 | dependency-reduced-pom.xml
23 | buildNumber.properties
24 | settings.xml
25 |
26 | # Created by https://www.gitignore.io/api/intellij
27 |
28 | ### Intellij ###
29 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
30 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
31 |
32 | # User-specific stuff:
33 | .idea/workspace.xml
34 | .idea/tasks.xml
35 |
36 | # Sensitive or high-churn files:
37 | .idea/dataSources/
38 | .idea/dataSources.ids
39 | .idea/dataSources.xml
40 | .idea/dataSources.local.xml
41 | .idea/sqlDataSources.xml
42 | .idea/dynamic.xml
43 | .idea/uiDesigner.xml
44 |
45 | # Gradle:
46 | .idea/gradle.xml
47 | .idea/libraries
48 |
49 | # Mongo Explorer plugin:
50 | .idea/mongoSettings.xml
51 |
52 | ## File-based project format:
53 | *.iws
54 |
55 | ## Plugin-specific files:
56 |
57 | # IntelliJ
58 | /out/
59 |
60 | # mpeltonen/sbt-idea plugin
61 | .idea_modules/
62 |
63 | # JIRA plugin
64 | atlassian-ide-plugin.xml
65 |
66 | # Crashlytics plugin (for Android Studio and IntelliJ)
67 | com_crashlytics_export_strings.xml
68 | crashlytics.properties
69 | crashlytics-build.properties
70 | fabric.properties
71 |
72 | ### Intellij Patch ###
73 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
74 |
75 | # *.iml
76 | # modules.xml
77 | # .idea/misc.xml
78 | # *.ipr
79 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/Header.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.util.BlockWriter;
20 | import com.overzealous.remark.util.StringUtils;
21 | import org.jsoup.nodes.Element;
22 |
23 | /**
24 | * Handles header nodes (h1 through h6)
25 | *
26 | * @author Phil DeJarnett
27 | */
28 | public class Header extends AbstractNodeHandler {
29 |
30 | /**
31 | * Renders a header node (h1..h6). If enabled, also handles the headerID attribute.
32 | *
33 | * @param parent The previous node walker, in case we just want to remove an element.
34 | * @param node Node to handle
35 | * @param converter Parent converter for this object.
36 | */
37 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
38 | int depth = Integer.parseInt(node.tagName().substring(1, 2));
39 | BlockWriter out = converter.output;
40 | out.startBlock();
41 | StringUtils.multiply(out, '#', depth);
42 | out.print(' ');
43 | out.print(converter.getInlineContent(this, node).replace("\n", " "));
44 | out.print(' ');
45 | StringUtils.multiply(out, '#', depth);
46 | if(converter.options.headerIds && node.hasAttr("id")) {
47 | out.printf(" {#%s}", node.attr("id"));
48 | }
49 | out.endBlock();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/NodeHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import org.jsoup.nodes.Element;
20 | import org.jsoup.nodes.TextNode;
21 |
22 | /**
23 | * Interface for classes that handle processing HTML Elements.
24 | * @author Phil DeJarnett
25 | */
26 | public interface NodeHandler {
27 |
28 | /**
29 | * Handles an HTML Element node. This is where most of the work is done.
30 | *
31 | * Which NodeHandler is used is based on the tagName of the element.
32 | *
33 | * @param parent The previous node walker, in case we just want to remove an element.
34 | * @param node Node to handle
35 | * @param converter Parent converter for this object.
36 | */
37 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter);
38 |
39 | /**
40 | * Handle a child text node.
41 | *
42 | * @param node Node to handle
43 | * @param converter Parent converter for this object.
44 | */
45 | public void handleTextNode(TextNode node, DocumentConverter converter);
46 |
47 | /**
48 | * Handle an ignored HTMLElement.
49 | * @param node Node to handle
50 | * @param converter Parent converter for this object.
51 | */
52 | public void handleIgnoredHTMLElement(Element node, DocumentConverter converter);
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/Image.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.util.BlockWriter;
20 | import org.jsoup.nodes.Element;
21 |
22 | /**
23 | * Handles img tags.
24 | * @author Phil DeJarnett
25 | */
26 | public class Image extends AbstractNodeHandler {
27 |
28 | /**
29 | * Creates a link reference to an image, and renders the correct output.
30 | *
31 | * @param parent The previous node walker, in case we just want to remove an element.
32 | * @param node Node to handle
33 | * @param converter Parent converter for this object.
34 | */
35 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
36 | String url = converter.cleaner.cleanUrl(node.attr("src"));
37 | String alt = node.attr("alt");
38 | if(alt == null || alt.trim().length() == 0) {
39 | alt = node.attr("title");
40 | if(alt == null) {
41 | alt = "";
42 | }
43 | }
44 | alt = converter.cleaner.clean(alt.trim());
45 | if(converter.options.inlineLinks) {
46 | if(alt.length() == 0) {
47 | alt = "Image";
48 | }
49 | converter.output.printf("", alt, url);
50 | } else {
51 | String linkId = converter.addLink(url, alt, true);
52 | // give a usable description based on filename whenever possible
53 | if(alt.length() == 0) {
54 | alt = linkId;
55 | }
56 | BlockWriter out = converter.output;
57 | if(alt.equals(linkId)) {
58 | out.printf("![%s][]", linkId);
59 | } else {
60 | out.printf("![%s][%s]", alt, linkId);
61 | }
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/PlainMarkdownTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import org.junit.Test;
20 |
21 | /**
22 | * @author Phil DeJarnett
23 | */
24 | public class PlainMarkdownTest extends RemarkTester {
25 |
26 | @Test public void testAbbr() throws Exception { test("abbr"); }
27 | @Test public void testAnchor() throws Exception { test("anchor"); }
28 | @Test public void testBlockQuote() throws Exception { test("blockquote"); }
29 | @Test public void testHeader() throws Exception { test("header"); }
30 | @Test public void testBreak() throws Exception { test("break"); }
31 | @Test public void testCodeblock() throws Exception { test("codeblock"); }
32 | @Test public void testDefinitions() throws Exception { test("definitions"); }
33 | @Test public void testHorizontalRule() throws Exception { test("horizontalrule"); }
34 | @Test public void testImage() throws Exception { test("image"); }
35 | @Test public void testInlineCode() throws Exception { test("inlinecode"); }
36 | @Test public void testInlineStyle() throws Exception { test("inlinestyle"); }
37 | @Test public void testInlineStyleEmptyBreak() throws Exception { test("inlinestyle-emptybreak"); }
38 | @Test public void testListOrdered() throws Exception { test("listordered"); }
39 | @Test public void testListUnordered() throws Exception { test("listunordered"); }
40 | @Test public void testParagraph() throws Exception { test("paragraph"); }
41 | @Test public void testTables() throws Exception { test("tables"); }
42 | @Test public void testUnknownHTML() throws Exception { test("unknownHTML"); }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/List.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.util.BlockWriter;
20 | import org.jsoup.nodes.Element;
21 |
22 | /**
23 | * Handles ol and ul lists.
24 | * @author Phil DeJarnett
25 | */
26 | public class List extends AbstractNodeHandler {
27 |
28 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
29 | // the first node doesn't get a linebreak
30 | boolean first = true;
31 | // if this is an ol, it's numbered.
32 | boolean numericList = node.tagName().equals("ol");
33 | // keep track of where we are in the list.
34 | int listCounter = 1;
35 |
36 | // we need to store this, because we're going to replace it for each li below (for padding).
37 | BlockWriter parentWriter = converter.output;
38 | parentWriter.startBlock();
39 | for(final Element child : node.children()) {
40 | // handle linebreaks between li's
41 | if(first) {
42 | first = false;
43 | } else {
44 | parentWriter.println();
45 | }
46 | // handle starting character
47 | if(numericList) {
48 | parentWriter.print(listCounter);
49 | parentWriter.print(". ");
50 | if(listCounter < 10) {
51 | parentWriter.print(' ');
52 | }
53 | } else {
54 | parentWriter.print(" * ");
55 | }
56 |
57 | // now, recurse downward, padding the beginning of each line so it looks nice.
58 | converter.output = new BlockWriter(parentWriter).setPrependNewlineString(" ", true);
59 | converter.walkNodes(this, child, converter.blockNodes);
60 | listCounter++;
61 | }
62 | // cleanup
63 | parentWriter.endBlock();
64 | converter.output = parentWriter;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/Codeblock.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.Options;
20 | import com.overzealous.remark.util.BlockWriter;
21 | import com.overzealous.remark.util.StringUtils;
22 | import org.jsoup.nodes.Element;
23 |
24 | /**
25 | * Handles preformatted sections (pre), renders them as code blocks.
26 | *
27 | * @author Phil DeJarnett
28 | */
29 | public class Codeblock extends AbstractNodeHandler {
30 |
31 | /**
32 | * Converts a pre-formatted block of code.
33 | * Depending on the options, this may render as a block with four spaces added to the beginning,
34 | * or as a fenced code block.
35 | *
36 | * @param parent The previous node walker, in case we just want to remove an element.
37 | * @param node Node to handle
38 | * @param converter Parent converter for this object.
39 | */
40 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
41 | BlockWriter out;
42 | Options.FencedCodeBlocks fenced = converter.options.getFencedCodeBlocks();
43 | if(fenced.isEnabled()) {
44 | String fence = StringUtils.multiply(fenced.getSeparatorCharacter(),
45 | converter.options.fencedCodeBlocksWidth);
46 | out = converter.output;
47 | converter.output.startBlock();
48 | out.println(fence);
49 | out.write(converter.cleaner.cleanCode(node));
50 | out.println();
51 | out.print(fence);
52 | converter.output.endBlock();
53 | } else {
54 | converter.output.startBlock();
55 | out = new BlockWriter(converter.output).setPrependNewlineString(" ");
56 | out.write(converter.cleaner.cleanCode(node));
57 | converter.output.endBlock();
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/MultiMarkdownTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.Options;
20 | import com.overzealous.remark.Remark;
21 | import org.junit.Test;
22 |
23 | /**
24 | * @author Phil DeJarnett
25 | */
26 | public class MultiMarkdownTest extends RemarkTester {
27 |
28 | @Override
29 | public Remark setupRemark() {
30 | return new Remark(Options.multiMarkdown());
31 | }
32 |
33 | @Test public void testAbbr() throws Exception { test("abbr"); }
34 | @Test public void testAnchor() throws Exception { test("anchor"); }
35 | @Test public void testBlockQuote() throws Exception { test("blockquote"); }
36 | @Test public void testHeader() throws Exception { test("header"); }
37 | @Test public void testBreak() throws Exception { test("break"); }
38 | @Test public void testCodeblock() throws Exception { test("codeblock"); }
39 | @Test public void testDefinitions() throws Exception { test("definitions", "enabled"); }
40 | @Test public void testHorizontalRule() throws Exception { test("horizontalrule"); }
41 | @Test public void testImage() throws Exception { test("image"); }
42 | @Test public void testInlineCode() throws Exception { test("inlinecode"); }
43 | @Test public void testInlineStyle() throws Exception { test("inlinestyle"); }
44 | @Test public void testListOrdered() throws Exception { test("listordered"); }
45 | @Test public void testListUnordered() throws Exception { test("listunordered"); }
46 | @Test public void testParagraph() throws Exception { test("paragraph"); }
47 | @Test public void testTables() throws Exception { test("tables", "multimarkdown"); }
48 | @Test public void testUnknownHTML() throws Exception { test("unknownHTML"); }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/GithubTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.Options;
20 | import com.overzealous.remark.Remark;
21 | import org.junit.Test;
22 |
23 | /**
24 | * @author Phil DeJarnett
25 | */
26 | public class GithubTest extends RemarkTester {
27 |
28 | @Override
29 | public Remark setupRemark() {
30 | return new Remark(Options.github());
31 | }
32 |
33 | @Test public void testAbbr() throws Exception { test("abbr"); }
34 | @Test public void testAnchor() throws Exception { test("anchor", "autolink"); }
35 | @Test public void testBlockQuote() throws Exception { test("blockquote"); }
36 | @Test public void testHeader() throws Exception { test("header"); }
37 | @Test public void testBreak() throws Exception { test("break", "hardwrap"); }
38 | @Test public void testCodeblock() throws Exception { test("codeblock", "fenced-backtick"); }
39 | @Test public void testDefinitions() throws Exception { test("definitions"); }
40 | @Test public void testHorizontalRule() throws Exception { test("horizontalrule"); }
41 | @Test public void testImage() throws Exception { test("image"); }
42 | @Test public void testInlineCode() throws Exception { test("inlinecode"); }
43 | @Test public void testInlineStyle() throws Exception { test("inlinestyle"); }
44 | @Test public void testListOrdered() throws Exception { test("listordered"); }
45 | @Test public void testListUnordered() throws Exception { test("listunordered"); }
46 | @Test public void testParagraph() throws Exception { test("paragraph"); }
47 | @Test public void testTables() throws Exception { test("tables", "codeblock"); }
48 | @Test public void testUnknownHTML() throws Exception { test("unknownHTML"); }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/MarkdownExtraTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.Options;
20 | import com.overzealous.remark.Remark;
21 | import org.junit.Test;
22 |
23 | /**
24 | * @author Phil DeJarnett
25 | */
26 | public class MarkdownExtraTest extends RemarkTester {
27 |
28 | @Override
29 | public Remark setupRemark() {
30 | return new Remark(Options.markdownExtra());
31 | }
32 |
33 | @Test public void testAbbr() throws Exception { test("abbr", "enabled"); }
34 | @Test public void testAnchor() throws Exception { test("anchor"); }
35 | @Test public void testBlockQuote() throws Exception { test("blockquote"); }
36 | @Test public void testHeader() throws Exception { test("header", "headerids"); }
37 | @Test public void testBreak() throws Exception { test("break"); }
38 | @Test public void testCodeblock() throws Exception { test("codeblock", "fenced-tilde"); }
39 | @Test public void testDefinitions() throws Exception { test("definitions", "enabled"); }
40 | @Test public void testHorizontalRule() throws Exception { test("horizontalrule"); }
41 | @Test public void testImage() throws Exception { test("image"); }
42 | @Test public void testInlineCode() throws Exception { test("inlinecode"); }
43 | @Test public void testInlineStyle() throws Exception { test("inlinestyle"); }
44 | @Test public void testListOrdered() throws Exception { test("listordered"); }
45 | @Test public void testListUnordered() throws Exception { test("listunordered"); }
46 | @Test public void testParagraph() throws Exception { test("paragraph"); }
47 | @Test public void testTables() throws Exception { test("tables", "markdownextra"); }
48 | @Test public void testUnknownHTML() throws Exception { test("unknownHTML"); }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/PegdownTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.Options;
20 | import com.overzealous.remark.Remark;
21 | import org.junit.Test;
22 |
23 | /**
24 | * @author Phil DeJarnett
25 | */
26 | public class PegdownTest extends RemarkTester {
27 |
28 | @Override
29 | public Remark setupRemark() {
30 | return new Remark(Options.pegdownAllExtensions());
31 | }
32 |
33 | @Test public void testAbbr() throws Exception { test("abbr", "enabled"); }
34 | @Test public void testAnchor() throws Exception { test("anchor", "autolink"); }
35 | @Test public void testBlockQuote() throws Exception { test("blockquote"); }
36 | @Test public void testHeader() throws Exception { test("header"); }
37 | @Test public void testBreak() throws Exception { test("break", "hardwrap"); }
38 | @Test public void testCodeblock() throws Exception { test("codeblock", "fenced-tilde"); }
39 | @Test public void testDefinitions() throws Exception { test("definitions", "enabled"); }
40 | @Test public void testHorizontalRule() throws Exception { test("horizontalrule"); }
41 | @Test public void testImage() throws Exception { test("image"); }
42 | @Test public void testInlineCode() throws Exception { test("inlinecode"); }
43 | @Test public void testInlineStyle() throws Exception { test("inlinestyle", "inword-removed"); }
44 | @Test public void testListOrdered() throws Exception { test("listordered"); }
45 | @Test public void testListUnordered() throws Exception { test("listunordered"); }
46 | @Test public void testParagraph() throws Exception { test("paragraph"); }
47 | @Test public void testTables() throws Exception { test("tables", "multimarkdown"); }
48 | @Test public void testUnknownHTML() throws Exception { test("unknownHTML"); }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/RemarkTester.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.Remark;
20 | import com.overzealous.remark.util.TestUtils;
21 | import org.junit.Assert;
22 | import org.junit.Before;
23 |
24 | /**
25 | * @author Phil DeJarnett
26 | */
27 | public abstract class RemarkTester {
28 |
29 | private static final String BASE_PATH = "/conversions/";
30 | private static final String INPUT_PATH = BASE_PATH+"html/";
31 | private static final String MD_PATH = BASE_PATH+"markdown/";
32 | private static final String HTML_EXT = ".html";
33 | private static final String MD_EXT = ".md";
34 |
35 | @SuppressWarnings({"WeakerAccess"})
36 | Remark remark;
37 | @SuppressWarnings({"WeakerAccess", "CanBeFinal"})
38 | String baseURI = "http://www.example.com/";
39 |
40 | /**
41 | * Override to change the remark method
42 | * @return A Remark instance
43 | */
44 | Remark setupRemark() {
45 | return new Remark();
46 | }
47 |
48 | @Before
49 | public void setUp() throws Exception {
50 | this.remark = setupRemark();
51 | Assert.assertNotNull(this.remark);
52 | }
53 |
54 |
55 | void test(String testName) throws Exception {
56 | test(testName, null);
57 | }
58 |
59 | @SuppressWarnings({"RedundantThrows"})
60 | void test(String testName, String option) throws Exception {
61 | String input = TestUtils.readResourceToString(INPUT_PATH + testName + HTML_EXT);
62 | if(option == null) {
63 | option = "";
64 | } else {
65 | option = '-' + option;
66 | }
67 | String expected = TestUtils.readResourceToString(MD_PATH + testName + option + MD_EXT);
68 | String converted = remark.convertFragment(input, baseURI);
69 | if(!converted.equals(expected)) {
70 | System.out.println("==============================");
71 | System.out.println(expected);
72 | System.out.println("------------------------------");
73 | System.out.println(converted);
74 | System.out.println("==============================");
75 | }
76 | Assert.assertEquals(expected, converted);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/convert/DocumentConverterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import com.overzealous.remark.Options;
20 | import org.junit.Assert;
21 | import org.junit.Before;
22 | import org.junit.Test;
23 |
24 | /**
25 | * @author Phil DeJarnett
26 | */
27 | public class DocumentConverterTest {
28 |
29 | private DocumentConverter dc;
30 |
31 | private static final String LINK_URL = "http://www.example.com/file.html";
32 | private static final String IMAGE_URL = "http://www.example.com/image.jpg";
33 | private static final String IMAGE_NOFILE_URL = "http://www.example.com/blah/";
34 | private static final String IMAGE_INVALID_URL = "http://www.example.com/_!!_";
35 |
36 | @Before
37 | public void setUp() throws Exception {
38 | dc = new DocumentConverter(Options.markdown());
39 | }
40 |
41 | @Test
42 | public void testSimpleLink() throws Exception {
43 | Assert.assertEquals("test", dc.cleanLinkId(LINK_URL, "test", false));
44 | Assert.assertEquals("test-test", dc.cleanLinkId(LINK_URL, "test-test", false));
45 | Assert.assertEquals("test test", dc.cleanLinkId(LINK_URL, "test\ntest", false));
46 | }
47 |
48 | @Test
49 | public void testReplacementLinks() throws Exception {
50 | Assert.assertEquals("test_test", dc.cleanLinkId(LINK_URL, "test*&^$#˜∂test", false));
51 | Assert.assertEquals("test", dc.cleanLinkId(LINK_URL, "&(^test", false));
52 | Assert.assertEquals("test", dc.cleanLinkId(LINK_URL, "test^%$", false));
53 | }
54 |
55 | @Test
56 | public void testGenericLinks() throws Exception {
57 | Assert.assertEquals("Link 1", dc.cleanLinkId(LINK_URL, "*(&(*&(", false));
58 | Assert.assertEquals("Link 2", dc.cleanLinkId(LINK_URL, "_!!\n!!_", false));
59 | }
60 |
61 | @Test
62 | public void testGenericImages() throws Exception {
63 | Assert.assertEquals("Image 1", dc.cleanLinkId(IMAGE_NOFILE_URL, "*(&(*&(", true));
64 | Assert.assertEquals("Image 2", dc.cleanLinkId(IMAGE_NOFILE_URL, "_!!\n!!_", true));
65 | Assert.assertEquals("image.jpg", dc.cleanLinkId(IMAGE_URL, "!", true));
66 | Assert.assertEquals("Image 3", dc.cleanLinkId(IMAGE_INVALID_URL, "!", true));
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/convert/Anchor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.convert;
18 |
19 | import org.jsoup.nodes.Element;
20 |
21 | import java.util.regex.Pattern;
22 |
23 | /**
24 | * Handles anchor (a) tags, both links and named anchors.
25 | * @author Phil DeJarnett
26 | */
27 | public class Anchor extends AbstractNodeHandler {
28 |
29 | private static final Pattern INLINE_LINK_ESCAPE = Pattern.compile("([\\(\\)])");
30 | private static final String INLINE_LINK_REPLACEMENT = "\\\\$1";
31 |
32 | /**
33 | * Creates a link reference, and renders the correct output.
34 | *
35 | * If this happens to be a named anchor, then it is simply removed from output.
36 | *
37 | * @param parent The previous node walker, in case we just want to remove an element.
38 | * @param node Node to handle
39 | * @param converter Parent converter for this object.
40 | */
41 | public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
42 | if(node.hasAttr("href") && node.attr("href").trim().length() > 0) {
43 | // Must be a real link.
44 | String url = converter.cleaner.cleanUrl(node.attr("href"));
45 | String label = converter.getInlineContent(this, node);
46 |
47 | if(label.length() > 0) {
48 | if(converter.options.autoLinks && url.equals(label)) {
49 | // embed autolink
50 | converter.output.write(label);
51 | } else if(converter.options.inlineLinks) {
52 | // standard link
53 | if(converter.options.fixPegdownStrongEmphasisInLinks) {
54 | label = label.replace("***", "**");
55 | }
56 | converter.output.printf("[%s](%s)", label, url);
57 | } else {
58 | // standard link
59 | if(converter.options.fixPegdownStrongEmphasisInLinks) {
60 | label = label.replace("***", "**");
61 | }
62 | String linkId = converter.addLink(url, label, false);
63 | if(label.equals(linkId)) {
64 | converter.output.printf("[%s][]", label);
65 | } else {
66 | converter.output.printf("[%s][%s]", label, linkId);
67 | }
68 | }
69 | } // else, ignore links with no label
70 | } else {
71 | // named anchor, not a link
72 | // simply remove it from the flow.
73 | converter.walkNodes(parent, node);
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/manual/_template.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
62 |
65 |
66 |
67 | head 1
63 | head 2
64 |
68 |
72 |
73 | one
69 | two
70 | three
71 | Remark
22 |
34 |
` is converted to just a single linebreak, instead of `(space)(space)(newline)`, common in most third-party markdown renderers
36 | * Autolinks — a link that has the same content as it's label (and starts with http or https) is simply rendered as is, like `http://www.overzealous.com`
37 | * [Markdown Extra definition lists][]
38 | * [Markdown Extra abbreviations][]
39 | * [Markdown Extra header IDs][]
40 | * Fenced code blocks, using either [Markdown Extra's format][Markdown Extra fenced code block] using `~~~`, or [Github's format][Github fenced code block] using ` ``` `
41 | * Customization of allowed HTML tags - not really recommended.
42 |
43 | The basic theory is that you match the extensions to your Markdown conversion library.
44 |
45 | ### Dependencies
46 |
47 | **Remark** depends on [jsoup][] and [Apache Commons Lang 3][]. If you want to use it from the command line, it also depends on [Apache Commons CLI][]. Alternatively, you can download the standalone version of the Jar, which contains all the dependencies.
48 |
49 | During testing, **Remark** also depends on some additional libraries, which are automatically downloaded by the gradle build script.
50 |
51 | [Markdown]: http://daringfireball.net/projects/markdown/
52 | [Markdown Extra]: http://michelf.com/projects/php-markdown/extra/
53 | [Markdown Extra tables]: http://michelf.com/projects/php-markdown/extra/#table
54 | [Markdown Extra definition lists]: http://michelf.com/projects/php-markdown/extra/#def-list
55 | [Markdown Extra fenced code block]: http://michelf.com/projects/php-markdown/extra/#fenced-code-blocks
56 | [Markdown Extra abbreviations]: http://michelf.com/projects/php-markdown/extra/#abbr
57 | [Markdown Extra header IDs]: http://michelf.com/projects/php-markdown/extra/#header-id
58 | [MultiMarkdown]: http://fletcherpenney.net/multimarkdown/
59 | [MultiMarkdown tables]: http://fletcher.github.com/peg-multimarkdown/#tables
60 | [Github fenced code block]: http://github.github.com/github-flavored-markdown/
61 | [dojo_rte]: http://dojotoolkit.org/reference-guide/dijit/Editor.html
62 | [other_rtes]: http://www.queness.com/post/212/10-jquery-and-non-jquery-javascript-rich-text-editors
63 | [jsoup]: http://jsoup.org/
64 | [jsoup license]: http://jsoup.org/license
65 | [Apache Commons Lang 3]: http://commons.apache.org/lang/
66 | [Apache Commons CLI]: http://commons.apache.org/cli/
67 | [Apache 2.0 License]: http://www.apache.org/licenses/LICENSE-2.0
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/util/BlockWriterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.util;
18 |
19 | import org.junit.Assert;
20 | import org.junit.Test;
21 |
22 | /**
23 | * @author Phil DeJarnett
24 | */
25 | public class BlockWriterTest {
26 |
27 | @Test
28 | public void testWriteTwoBlocks() throws Exception {
29 | BlockWriter bw = BlockWriter.create();
30 | bw.writeBlock("block1");
31 | bw.writeBlock("block2");
32 |
33 | Assert.assertEquals("block1\n\nblock2", bw.toString());
34 | }
35 |
36 | @Test
37 | public void testWriteInlineThenBlock() throws Exception {
38 | BlockWriter bw = BlockWriter.create();
39 | bw.write("inline1");
40 | bw.writeBlock("block1");
41 |
42 | Assert.assertEquals("inline1\n\nblock1", bw.toString());
43 | }
44 |
45 | @Test
46 | public void testWriteBlockThenInlineThenBlock() throws Exception {
47 | BlockWriter bw = BlockWriter.create();
48 | bw.writeBlock("block1");
49 | bw.write("inline1");
50 | bw.writeBlock("block2");
51 |
52 | Assert.assertEquals("block1\n\ninline1\n\nblock2", bw.toString());
53 | }
54 |
55 | @Test
56 | public void testWriteManualBlock() throws Exception {
57 | BlockWriter bw = BlockWriter.create();
58 | bw.startBlock();
59 | bw.print("hello");
60 | bw.println();
61 | bw.print("world");
62 | bw.endBlock();
63 | bw.write("inline");
64 | bw.write("1");
65 | bw.startBlock();
66 | bw.write("block1");
67 | bw.endBlock();
68 |
69 | Assert.assertEquals("hello\nworld\n\ninline1\n\nblock1", bw.toString());
70 | }
71 |
72 | @Test
73 | public void testWriteNestedBlocks() throws Exception {
74 | BlockWriter bw = BlockWriter.create();
75 | bw.startBlock();
76 | bw.write("hello");
77 | bw.startBlock();
78 | bw.write("world");
79 | bw.endBlock();
80 | bw.endBlock();
81 |
82 | Assert.assertEquals(0, bw.getBlockDepth());
83 |
84 | Assert.assertEquals("hello\n\nworld", bw.toString());
85 | }
86 |
87 | @Test
88 | public void testPrintf() throws Exception {
89 | BlockWriter bw = BlockWriter.create();
90 | bw.printf("%s", "hello");
91 | bw.printf("%d", 42);
92 | bw.writeBlock("block1");
93 |
94 | Assert.assertEquals("hello42\n\nblock1", bw.toString());
95 | }
96 |
97 | @Test
98 | public void testPrependChar() throws Exception {
99 | BlockWriter bw = BlockWriter.create();
100 | bw.setPrependNewlineString("XXXX");
101 | bw.write('a');
102 |
103 | Assert.assertEquals("XXXXa", bw.toString());
104 | }
105 |
106 | @Test
107 | public void testPrependCharBuffer() throws Exception {
108 | BlockWriter bw = BlockWriter.create();
109 | bw.setPrependNewlineString("XXXX");
110 | bw.write("abc\ndef\nghi".toCharArray());
111 |
112 | Assert.assertEquals("XXXXabc\nXXXXdef\nXXXXghi", bw.toString());
113 | }
114 |
115 | @Test
116 | public void testPrependString() throws Exception {
117 | BlockWriter bw = BlockWriter.create();
118 | bw.setPrependNewlineString("XXXX");
119 | bw.write("abc\n\ndef\nghi");
120 | bw.write("\njkl");
121 |
122 | Assert.assertEquals("XXXXabc\nXXXX\nXXXXdef\nXXXXghi\nXXXXjkl", bw.toString());
123 | }
124 |
125 | @Test
126 | public void testPrependNotFirst() throws Exception {
127 | BlockWriter bw = BlockWriter.create();
128 | bw.setPrependNewlineString("XXXX", true);
129 | bw.write("- ");
130 | bw.write("abc\ndef\nghi");
131 |
132 | Assert.assertEquals("- abc\nXXXXdef\nXXXXghi", bw.toString());
133 | }
134 |
135 | @Test
136 | public void testPrependBlocks() throws Exception {
137 | BlockWriter bw = BlockWriter.create();
138 | bw.setPrependNewlineString("XXXX");
139 | bw.printBlock("abc\ndef");
140 | bw.printBlock("ghi\njkl");
141 |
142 | Assert.assertEquals("XXXXabc\nXXXXdef\nXXXX\nXXXXghi\nXXXXjkl", bw.toString());
143 | }
144 |
145 | @Test
146 | public void testEmptyBlocks() throws Exception {
147 | BlockWriter bw = BlockWriter.create();
148 | bw.writeBlock("block1");
149 | bw.startBlock();
150 | bw.startBlock();
151 | bw.writeBlock("block2");
152 | bw.endBlock();
153 | bw.endBlock();
154 |
155 | Assert.assertEquals("block1\n\nblock2", bw.toString());
156 | }
157 |
158 | @Test
159 | public void testEmptyAutoBlocks() throws Exception {
160 | BlockWriter bw = BlockWriter.create();
161 | bw.writeBlock("block1");
162 | bw.startBlock();
163 | bw.write("inline1");
164 | bw.startBlock();
165 | bw.writeBlock("block2");
166 | bw.endBlock();
167 | bw.write("inline2");
168 | bw.endBlock();
169 |
170 | Assert.assertEquals("block1\n\ninline1\n\nblock2\n\ninline2", bw.toString());
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/util/MarkdownTableCell.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.util;
18 |
19 | /**
20 | * This class contains the contents of a table cell. It's used to help keep track of
21 | * information about the table so the final table can be built with clean formatting.
22 | *
23 | * @author Phil DeJarnett
24 | */
25 | public class MarkdownTableCell {
26 |
27 | private MarkdownTable.Alignment alignment = MarkdownTable.Alignment.LEFT;
28 |
29 | private String contents = "";
30 |
31 | private int colspan = 1;
32 |
33 | /**
34 | * Creates a new, empty MarkdownTableCell
35 | */
36 | @SuppressWarnings({"UnusedDeclaration"})
37 | public MarkdownTableCell() {
38 | this("", MarkdownTable.Alignment.LEFT, 1);
39 | }
40 |
41 | /**
42 | * Creates a new MarkdownTableCell with only contents
43 | * @param contents The contents of this cell
44 | */
45 | public MarkdownTableCell(String contents) {
46 | this(contents, MarkdownTable.Alignment.LEFT, 1);
47 | }
48 |
49 | /**
50 | * Creates a new MarkdownTableCell with contents and alignment
51 | * @param contents The contents of this cell
52 | * @param alignment The alignment of this cell (if specified)
53 | */
54 | public MarkdownTableCell(String contents, MarkdownTable.Alignment alignment) {
55 | this(contents, alignment, 1);
56 | }
57 |
58 | /**
59 | * Creates a new MarkdownTableCell with contents and a colspan
60 | * @param contents The contents of this cell
61 | * @param colspan The number of columns this cell spans
62 | */
63 | public MarkdownTableCell(String contents, int colspan) {
64 | this(contents, MarkdownTable.Alignment.LEFT, colspan);
65 | }
66 |
67 | /**
68 | * Creates a new MarkdownTableCell with contents and a colspan
69 | * @param contents The contents of this cell
70 | * @param alignment The alignment of this cell (if specified)
71 | * @param colspan The number of columns this cell spans
72 | */
73 | public MarkdownTableCell(String contents, MarkdownTable.Alignment alignment, int colspan) {
74 | this.setContents(contents);
75 | this.setAlignment(alignment);
76 | this.setColspan(colspan);
77 | }
78 |
79 | /**
80 | * Gets the text-alignment of this cell
81 | * @return The alignment of this cell
82 | */
83 | public MarkdownTable.Alignment getAlignment() {
84 | return alignment;
85 | }
86 |
87 | /**
88 | * Sets the text-alignment. Note: the alignment cannot be null.
89 | * @param alignment The new alignment
90 | */
91 | public void setAlignment(MarkdownTable.Alignment alignment) {
92 | if(alignment == null) {
93 | throw new IllegalArgumentException("Alignment cannot be null");
94 | }
95 | this.alignment = alignment;
96 | }
97 |
98 | public String getContents() {
99 | return contents;
100 | }
101 |
102 | /**
103 | * Sets the contents of this cell.
104 | * If the contents contain any linebreaks, they will be replaced with spaces.
105 | *
106 | * @param contents The new cell contents
107 | */
108 | public void setContents(String contents) {
109 | if(contents == null) {
110 | contents = "";
111 | }
112 | // We don't allow linebreaks in a table cell
113 | this.contents = contents.replace("\n", " ");
114 | }
115 |
116 | public int getColspan() {
117 | return colspan;
118 | }
119 |
120 | /**
121 | * Sets the number of columns this cell spans. If the colspan is less than 1, it is set to 1.
122 | * @param colspan The new colspan
123 | */
124 | public void setColspan(int colspan) {
125 | if(colspan < 1) {
126 | colspan = 1;
127 | }
128 | this.colspan = colspan;
129 | }
130 |
131 | /**
132 | * Returns the number of characters needed to show this column.
133 | * It adds two to the content width, so there is padding around the content.
134 | * @return The width of this column in characters, plus 2 chars for spacing.
135 | */
136 | public int getWidth() {
137 | return this.contents.length() + 2;
138 | }
139 |
140 | @Override
141 | public String toString() {
142 | return "MarkdownTableCell{" +
143 | "colspan=" + colspan +
144 | ", alignment=" + alignment +
145 | ", contents='" + contents + '\'' +
146 | '}';
147 | }
148 |
149 | @Override
150 | public boolean equals(Object o) {
151 | if(this == o) { return true; }
152 | if(o == null || getClass() != o.getClass()) { return false; }
153 |
154 | MarkdownTableCell that = (MarkdownTableCell) o;
155 |
156 | return !(colspan != that.colspan ||
157 | alignment != that.alignment ||
158 | !contents.equals(that.contents));
159 | }
160 |
161 | @Override
162 | public int hashCode() {
163 | int result = alignment.hashCode();
164 | result = 31 * result + contents.hashCode();
165 | result = 31 * result + colspan;
166 | return result;
167 | }
168 | }
169 |
--------------------------------------------------------------------------------
/src/test/java/com/overzealous/remark/util/MarkdownTableTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.util;
18 |
19 | import org.junit.Assert;
20 | import org.junit.Test;
21 |
22 | import java.io.PrintWriter;
23 | import java.io.StringWriter;
24 | import java.util.List;
25 |
26 | /**
27 | * @author Phil DeJarnett
28 | */
29 | public class MarkdownTableTest {
30 |
31 | @Test
32 | public void testTable() throws Exception {
33 | MarkdownTable mt = new MarkdownTable();
34 | List
` is converted to just a single linebreak, instead of `(space)(space)(newline)`, common in most third-party markdown renderers
39 | * Autolinks — a link that has the same content as it's label (and starts with http or https) is simply rendered as is, like `http://www.overzealous.com`
40 | * [Markdown Extra definition lists][]
41 | * [Markdown Extra abbreviations][]
42 | * [Markdown Extra header IDs][]
43 | * Fenced code blocks, using either [Markdown Extra's format][Markdown Extra fenced code block] using `~~~`, or [Github's format][Github fenced code block] using ` ``` `
44 | * Customization of allowed HTML tags - not really recommended.
45 |
46 | The basic theory is that you match the extensions to your Markdown conversion library.
47 |
48 | ## A Note on Forking:
49 |
50 | Want to fork this project? *Great!* However, please note that I use [hgflow][] to manage the develop-release cycle. If you are uncomfortable with that, that's fine, too! Just switch to the **develop** branch before working, or I won't be able to easily merge the changes back in.
51 |
52 | Source code build is done via [Gradle][].
53 |
54 | ## Dependencies
55 |
56 | **Remark** depends on [jsoup][] and [Apache Commons Lang 3][]. If you want to use it from the command line, it also depends on [Apache Commons CLI][]. Alternatively, you can download the standalone version of the Jar, which contains all the dependencies.
57 |
58 | jsoup uses the [MIT License][jsoup license], which is roughly comparable to the [Apache 2.0 License][] used by Remark and the Apache dependencies.
59 |
60 | During testing, **Remark** also depends on some additional libraries, which are automatically downloaded by the gradle build script.
61 |
62 | ## License
63 |
64 | **Remark** is released under the [Apache 2.0 license][].
65 |
66 | Copyright 2011 OverZealous Creations, LLC
67 |
68 | Licensed under the Apache License, Version 2.0 (the "License");
69 | you may not use this file except in compliance with the License.
70 | You may obtain a copy of the License at
71 |
72 | http://www.apache.org/licenses/LICENSE-2.0
73 |
74 | Unless required by applicable law or agreed to in writing, software
75 | distributed under the License is distributed on an "AS IS" BASIS,
76 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
77 | See the License for the specific language governing permissions and
78 | limitations under the License.
79 |
80 | [Markdown]: http://daringfireball.net/projects/markdown/
81 | [Markdown Extra]: http://michelf.com/projects/php-markdown/extra/
82 | [Markdown Extra tables]: http://michelf.com/projects/php-markdown/extra/#table
83 | [Markdown Extra definition lists]: http://michelf.com/projects/php-markdown/extra/#def-list
84 | [Markdown Extra fenced code block]: http://michelf.com/projects/php-markdown/extra/#fenced-code-blocks
85 | [Markdown Extra abbreviations]: http://michelf.com/projects/php-markdown/extra/#abbr
86 | [Markdown Extra header IDs]: http://michelf.com/projects/php-markdown/extra/#header-id
87 | [MultiMarkdown]: http://fletcherpenney.net/multimarkdown/
88 | [MultiMarkdown tables]: http://fletcher.github.com/peg-multimarkdown/#tables
89 | [Github fenced code block]: http://github.github.com/github-flavored-markdown/
90 | [dojo_rte]: http://dojotoolkit.org/reference-guide/dijit/Editor.html
91 | [other_rtes]: http://www.queness.com/post/212/10-jquery-and-non-jquery-javascript-rich-text-editors
92 | [jsoup]: http://jsoup.org/
93 | [jsoup license]: http://jsoup.org/license
94 | [Apache Commons Lang 3]: http://commons.apache.org/lang/
95 | [Apache Commons CLI]: http://commons.apache.org/cli/
96 | [hgflow]: https://bitbucket.org/yinwm/hgflow/wiki/Home
97 | [Gradle]: http://gradle.org/
98 | [Apache 2.0 License]: http://www.apache.org/licenses/LICENSE-2.0
99 |
--------------------------------------------------------------------------------
/src/manual/examples.md:
--------------------------------------------------------------------------------
1 | # Examples
2 |
3 | Here are some basic input/output examples.
4 |
5 | ## Options: None (Straight Markdown)
6 |
7 | ### Hello World
8 |
9 | * HTML
10 |
11 |
24 |
28 | Ordered
29 |
30 |
34 |
35 | * Markdown
36 |
37 | *Unordered*
38 |
39 | * Item 1
40 | * Item 2
41 | * Item 3
42 |
43 | **Ordered**
44 |
45 | 1. Item 1
46 | 2. Item 2
47 | 3. Item 3
48 |
49 |
50 | ### Links
51 |
52 | * HTML
53 |
54 |
55 |
60 |
61 | * Markdown
62 |
63 | 1. [Example.com][]
64 | 2. [Google][]
65 | 3. [Yahoo!][Yahoo]
66 | 4. [Another Example.com][Example.com]
67 |
68 |
69 | [Example.com]: http://www.example.com
70 | [Google]: http://www.google.com
71 | [Yahoo]: http://www.yahoo.com
72 |
73 |
74 | ### Blockquotes and Code Samples
75 |
76 | * HTML
77 |
78 |
79 | Yes, Me Too
80 |
87 |
88 |
81 | I agree
82 |
86 |
83 | Top posting is confusing
84 |
85 | // Ain't Groovy Grand?
89 | // From: http://marxsoftware.blogspot.com/2011/06/ten-groovy-one-liners-to-impress-your.html
90 | (1..100).each{println "${it%3?'':'Fizz'}${it%5?'':'Buzz'}" ?: it }
91 |
92 |
93 | * Markdown
94 |
95 | > Yes, Me Too
96 | >
97 | > > I agree
98 | > >
99 | > > > Top posting is confusing
100 |
101 | // Ain't Groovy Grand?
102 | // From: http://marxsoftware.blogspot.com/2011/06/ten-groovy-one-liners-to-impress-your.html
103 | (1..100).each{println "${it%3?'':'Fizz'}${it%5?'':'Buzz'}" ?: it }
104 |
105 |
106 | ### Broken and Poor HTML
107 |
108 | In this example, you can see how Remark (along with JSoup) does it's best to salvage a usable result from bad input.
109 |
110 | * HTML
111 |
112 | Header 1
144 |
161 |
166 |
167 | * Markdown
168 |
169 | HTML
170 | : A markup language commonly used on the web.
171 |
172 | Markdown
173 | : A markup language specifically designed to be human-readable.
174 |
175 |
176 | ### Markdown Extra Tables
177 |
178 | * HTML
179 |
180 |
181 |
182 |
215 |
216 | * Markdown
217 |
218 | | | Grouping | |
219 | | First Header | Second Header | Third Header |
220 | |:------------ |:-------------:| ------------:|
221 | | Content | *Long Cell* | |
222 | | Content | **Cell** | Cell |
223 | | New Section | More | Data |
224 | | And more | And more | |
225 |
226 |
227 |
228 | ## Options: Pegdown (All Extensions)
229 |
230 | These are some unique results when the options are set to use Pegdown (All Extensions) special features.
231 |
232 | ### Autolinks & Entity / Smartquote Reversal
233 |
234 | * HTML
235 |
236 |
183 |
186 |
184 | Grouping
185 |
187 |
191 |
192 |
193 | First Header
188 | Second Header
189 | Third Header
190 |
194 |
197 | Content
195 | Long Cell
196 |
198 |
202 |
203 |
204 | Content
199 | Cell
200 | Cell
201 |
205 |
209 | New Section
206 | More
207 | Data
208 |
210 |
213 |
214 | And more
211 | And more
212 |
256 |
257 |
290 |
291 | * Markdown
292 |
293 | | | Grouping ||
294 | | First Header | Second Header | Third Header |
295 | |:------------ |:-------------:| ------------:|
296 | | Content | *Long Cell* ||
297 | | Content | **Cell** | Cell |
298 | | New Section | More | Data |
299 | | And more | And more ||
300 |
--------------------------------------------------------------------------------
/src/main/java/com/overzealous/remark/util/StringUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 OverZealous Creations, LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.overzealous.remark.util;
18 |
19 | import java.io.PrintWriter;
20 | import java.io.StringWriter;
21 |
22 | /**
23 | * A small collection of utilities for manipulating strings.
24 | *
25 | * @author Phil DeJarnett
26 | */
27 | public class StringUtils {
28 |
29 | /** Represents left alignment. */
30 | public static final int ALIGN_LEFT = -1;
31 | /** Represents centered alignment. */
32 | public static final int ALIGN_CENTER = 0;
33 | /** Represents right alignment. */
34 | public static final int ALIGN_RIGHT = 1;
35 |
36 | /**
37 | * Pads out a left-, right-, or center-aligned string using spaces up to the specified width.
38 | * @param s String to pad
39 | * @param width Minimum width of final string
40 | * @param alignment How to align the string < 0 means left, 0 means center, and > 0 means right
41 | * @return Padded string
42 | */
43 | @SuppressWarnings({"SameParameterValue", "SameParameterValue"})
44 | public static String align(String s, int width, int alignment) {
45 | return align(s, width, ' ', alignment);
46 | }
47 |
48 | /**
49 | * Pads out a left-, right-, or center-aligned string using the specified character up to the specified width.
50 | * @param s String to pad
51 | * @param width Minimum width of final string
52 | * @param paddingChar Character to pad with
53 | * @param alignment How to align the string < 0 means left, 0 means center, and > 0 means right
54 | * @return Padded string
55 | */
56 | public static String align(String s, int width, char paddingChar, int alignment) {
57 | if(s.length() < width) {
58 | int diff = width - s.length();
59 | String left = "";
60 | String right = "";
61 | if(alignment == 0) {
62 | int numLeftChars = diff/2;
63 | int numRightChars = numLeftChars + (diff % 2);
64 | left = multiply(paddingChar, numLeftChars);
65 | right = multiply(paddingChar, numRightChars);
66 | } else if(alignment < 0) {
67 | right = multiply(paddingChar, diff);
68 | } else {
69 | left = multiply(paddingChar, diff);
70 | }
71 | s = left + s + right;
72 | }
73 | return s;
74 | }
75 |
76 | /**
77 | * Pads out a left-, right-, or center-aligned string using spaces up to the specified width.
78 | * @param output Writer to output the centered string to
79 | * @param s String to pad
80 | * @param width Minimum width of final string
81 | * @param alignment How to align the string < 0 means left, 0 means center, and > 0 means right
82 | */
83 | public static void align(PrintWriter output, String s, int width, int alignment) {
84 | align(output, s, width, ' ', alignment);
85 | }
86 |
87 | /**
88 | * Pads out a left-, right-, or center-aligned string using the specified character up to the specified width.
89 | * @param output Writer to output the centered string to
90 | * @param s String to pad
91 | * @param width Minimum width of final string
92 | * @param paddingChar Character to pad with
93 | * @param alignment How to align the string < 0 means left, 0 means center, and > 0 means right
94 | */
95 | public static void align(PrintWriter output, String s, int width, char paddingChar, int alignment) {
96 | if(s.length() < width) {
97 | int diff = width - s.length();
98 | if(alignment == 0) {
99 | int numLeftChars = diff/2;
100 | int numRightChars = numLeftChars + (diff % 2);
101 | multiply(output, paddingChar, numLeftChars);
102 | output.write(s);
103 | multiply(output, paddingChar, numRightChars);
104 | } else if(alignment < 0) {
105 | output.write(s);
106 | multiply(output, paddingChar, diff);
107 | } else {
108 | multiply(output, paddingChar, diff);
109 | output.write(s);
110 | }
111 | } else {
112 | output.write(s);
113 | }
114 | }
115 |
116 | /**
117 | * Duplicates the given character {@code count} times.
118 | * If {@code count} is less than or equal to 0, the empty string is returned.
119 | * @param c Character to duplicate
120 | * @param count Number of times to duplicate
121 | * @return Duplicated string.
122 | */
123 | public static String multiply(char c, int count) {
124 | return multiply(String.valueOf(c), count);
125 | }
126 |
127 | /**
128 | * Duplicates the given string {@code count} times.
129 | * If {@code count} is less than or equal to 0, the empty string is returned.
130 | * @param s String to duplicate
131 | * @param count Number of times to duplicate
132 | * @return Duplicated string.
133 | */
134 | public static String multiply(String s, int count) {
135 | if(count < 1) {
136 | return "";
137 | } else {
138 | StringBuilder sb = new StringBuilder();
139 | for(int i=0; i
258 |
261 |
259 | Grouping
260 |
262 |
266 |
267 |
268 | First Header
263 | Second Header
264 | Third Header
265 |
269 |
272 | Content
270 | Long Cell
271 |
273 |
277 |
278 |
279 | Content
274 | Cell
275 | Cell
276 |
280 |
284 | New Section
281 | More
282 | Data
283 |
285 |
288 |
289 | And more
286 | And more
287 | > header;
62 | private final List
> body;
63 |
64 | private int cols;
65 | private int[] widths;
66 | private Alignment[] alignments;
67 |
68 | private boolean firstNewline = true;
69 |
70 |
71 | /**
72 | * Creates a new, empty MarkdownTable
73 | */
74 | public MarkdownTable() {
75 | this.header = new LinkedList
>();
76 | this.body = new LinkedList
>();
77 | }
78 |
79 | /**
80 | * Creates a new header row, and returns it so it can have cells added to it.
81 | *
82 | * @return A list that can have columns added to it.
83 | */
84 | public List