Hamar
11 | url: /2018/10-norwegen/02-hamar/
12 | description: Ein Spaziergang durch Hamar, Shoppen und ein Besuch im Norsk jernbanemusem, dem norwegischen Eisenbahnmuseum.
13 | image: files/2018/10-Norwegen/Hamar_Titel.jpg
14 | +++
23 |
--------------------------------------------------------------------------------
/testdata/TestPlugins/table/output.default.golden:
--------------------------------------------------------------------------------
1 | FirstnameLastnameAgeJillSmith50EveJackson94EmptyEnd
2 |
3 | ### With \| Character
4 |
5 | FirstnameWith \| CharacterAgeJillSmith50 Eve
6 | Jackson
7 | 94
8 |
9 | ### Tabelle mit thead, tfoot, and tbody
10 |
11 | Header content 1Header content 2Footer content 1Footer content 2Body content 1Body content 2Unglaublich tolle BeschreibungUnglaublich tolle Daten
12 |
13 | #### Pegel DUISBURG-RUHRORT
14 |
15 | Quelle: …
16 |
17 | ABABCDABC**Strong**[Link](http://example.com/link.html)_Italic_`var`bc
18 |
19 | 1
20 |
21 | 2
22 |
23 | 3
24 |
25 | 1
26 |
27 | 2
28 |
29 | 3
--------------------------------------------------------------------------------
/testdata/TestCommonmark/blockquote/output.default.golden:
--------------------------------------------------------------------------------
1 | > Some Quote
2 | > Next Line
3 |
4 | > Allowing an unimportant mistake to pass without comment is a wonderful social grace.
5 | >
6 | > Ideological differences are no excuse for rudeness.
7 |
8 | > This is the first level of quoting.
9 | >
10 | > > This is a paragraph in a nested blockquote.
11 | >
12 | > Back to the first level.
13 |
14 | > ## This is a header.
15 | >
16 | > 1. This is the first list item.
17 | > 2. This is the second list item.
18 | >
19 | > A code block:
20 | >
21 | > ```
22 | > return 1 < 2 ? shell_exec('echo $input | $markdown_script') : 0;
23 | > ```
--------------------------------------------------------------------------------
/testdata/TestCommonmark/p_tag/output.default.golden:
--------------------------------------------------------------------------------
1 | Some Content
2 |
3 | Text
4 |
5 | Some Text
6 |
7 | Some Content
8 |
9 | jmap –histo[:live]
10 |
11 | Sometimes a struct field, function, type, or even a whole package becomes
12 |
13 | redundant or unnecessary, but must be kept for compatibility with existing
14 |
15 | programs.
16 |
17 | To signal that an identifier should not be used, add a paragraph to its doc
18 |
19 | comment that begins with "Deprecated:" followed by some information about the
20 |
21 | deprecation.
22 |
23 | There are a few examples [in the standard library](https://golang.org/search?q=Deprecated:).
--------------------------------------------------------------------------------
/testdata/TestRealWorld/snippets/tweet/output.default.golden:
--------------------------------------------------------------------------------
1 | [Kroger @kroger\
2 | \
3 | As a company, it’s our responsibility to better support our Black associates, customers and allies. We know there is more work to do and will keep you updated on our progress, this is only the beginning. Black Lives Matter. \
4 | \
5 | \
6 | June 12th 2020\
7 | \
8 | 17 Retweets93 Likes](https://twitter.com/kroger/status/1271516803756425218)
--------------------------------------------------------------------------------
/testdata/TestCommonmark/heading/output.setext.golden:
--------------------------------------------------------------------------------
1 | Heading 1
2 | =========
3 |
4 | Heading 2
5 | ---------
6 |
7 | ### Heading 3
8 |
9 | #### Heading 4
10 |
11 | ##### Heading 5
12 |
13 | ###### Heading 6
14 |
15 | Heading 7
16 |
17 | Heading with Whitespace
18 | -----------------------
19 |
20 | Header Containing Newlines
21 | ---------------------------
22 |
23 | Heading One
24 | ==============
25 |
26 | [**Heading 2**](http://example.com/page.html)
27 |
28 | \#hashtag
29 | =========
30 |
31 | not title
32 | \-\-\----
33 |
34 | not title
35 | -
36 |
37 | not title
38 |
39 | -
40 |
41 | not title
42 | =
43 |
44 | not title
45 | \\-\\-\\-
--------------------------------------------------------------------------------
/testdata/TestCommonmark/p_tag/goldmark.golden:
--------------------------------------------------------------------------------
1 |
Some Content
2 |
Text
3 |
Some Text
4 |
Some Content
5 |
jmap –histo[:live]
6 |
Sometimes a struct field, function, type, or even a whole package becomes
7 |
redundant or unnecessary, but must be kept for compatibility with existing
8 |
programs.
9 |
To signal that an identifier should not be used, add a paragraph to its doc
10 |
comment that begins with "Deprecated:" followed by some information about the
13 |
--------------------------------------------------------------------------------
/testdata/TestRealWorld/snippets/github_about/output.default.golden:
--------------------------------------------------------------------------------
1 | ## About
2 |
3 | ⚙️
4 | Convert HTML to Markdown. Even works with whole websites.
5 |
6 | ### Topics
7 |
8 | [go](http://example.com/topics/go "Topic: go") [golang](http://example.com/topics/golang "Topic: golang") [html](http://example.com/topics/html "Topic: html") [html-to-markdown](http://example.com/topics/html-to-markdown "Topic: html-to-markdown") [markdown](http://example.com/topics/markdown "Topic: markdown")
9 |
10 | ### Resources
11 |
12 | [Readme](http://example.com#readme)
13 |
14 | ### License
15 |
16 | [MIT License](http://example.com/JohannesKaufmann/html-to-markdown/blob/master/LICENSE)
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: "\U0001F41B Bug"
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **HTML Input**
14 | ```html
15 |
Title
16 | ```
17 |
18 |
19 | **Generated Markdown**
20 | ````markdown
21 | # Title
22 | ````
23 |
24 | **Expected Markdown**
25 | ````markdown
26 | # Title!!!
27 | ````
28 |
29 | **Additional context**
30 | Add any other context about the problem here. For example, if you changed the default options or used a plugin. Also adding the version from the `go.mod` is helpful.
31 |
--------------------------------------------------------------------------------
/testdata/TestRealWorld/snippets/tweet/goldmark.golden:
--------------------------------------------------------------------------------
1 |
Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Vestibulum id ligula porta felis euismod semper.
12 | More
13 |
--------------------------------------------------------------------------------
/testdata/TestCommonmark/list_nested/output.dash.golden:
--------------------------------------------------------------------------------
1 | - foo
2 | - bar
3 | - baz
4 | - boo
5 |
6 | - Coffee
7 | - Tea
8 | - Black tea
9 | - Green tea
10 | - Milk
11 |
12 | # header1
13 |
14 | - Bullet list
15 | - Nested bullet
16 | - Sub-nested bullet etc
17 | - Bullet list item 2
18 |
19 | - One
20 | - One point one
21 | - One point two
22 |
23 | 1. One
24 | 1. One point one
25 | 2. One point two
26 |
27 | - 1
28 | - 2
29 | - 2.1
30 | - 2.2
31 | - 2.2.1
32 | - 2.2.2
33 | - 2.2.3
34 | - 3
35 |
36 | 1. 1
37 | 2. 2
38 | 1. 2.1
39 | 2. 2.2
40 | 1. 2.2.1
41 | 2. 2.2.2
42 | 3. 2.2.3
43 | 4. 3
44 |
45 | - First Thing
46 |
47 | Second Thing
48 | - Nested First Thing
49 |
50 | Nested Thing
51 |
52 | 1. First Thing
53 |
54 | Second Thing
55 | 1. Nested First Thing
56 |
57 | Nested Thing
58 |
59 | 2. Date:
60 |
61 | 20.02.2021
62 |
63 | 26\. Mai - 3. Juni
--------------------------------------------------------------------------------
/testdata/TestCommonmark/list_nested/output.plus.golden:
--------------------------------------------------------------------------------
1 | + foo
2 | + bar
3 | + baz
4 | + boo
5 |
6 | + Coffee
7 | + Tea
8 | + Black tea
9 | + Green tea
10 | + Milk
11 |
12 | # header1
13 |
14 | + Bullet list
15 | + Nested bullet
16 | + Sub-nested bullet etc
17 | + Bullet list item 2
18 |
19 | + One
20 | + One point one
21 | + One point two
22 |
23 | 1. One
24 | 1. One point one
25 | 2. One point two
26 |
27 | + 1
28 | + 2
29 | + 2.1
30 | + 2.2
31 | + 2.2.1
32 | + 2.2.2
33 | + 2.2.3
34 | + 3
35 |
36 | 1. 1
37 | 2. 2
38 | 1. 2.1
39 | 2. 2.2
40 | 1. 2.2.1
41 | 2. 2.2.2
42 | 3. 2.2.3
43 | 4. 3
44 |
45 | + First Thing
46 |
47 | Second Thing
48 | + Nested First Thing
49 |
50 | Nested Thing
51 |
52 | 1. First Thing
53 |
54 | Second Thing
55 | 1. Nested First Thing
56 |
57 | Nested Thing
58 |
59 | 2. Date:
60 |
61 | 20.02.2021
62 |
63 | 26\. Mai - 3. Juni
--------------------------------------------------------------------------------
/testdata/TestCommonmark/list_nested/output.asterisks.golden:
--------------------------------------------------------------------------------
1 | * foo
2 | * bar
3 | * baz
4 | * boo
5 |
6 | * Coffee
7 | * Tea
8 | * Black tea
9 | * Green tea
10 | * Milk
11 |
12 | # header1
13 |
14 | * Bullet list
15 | * Nested bullet
16 | * Sub-nested bullet etc
17 | * Bullet list item 2
18 |
19 | * One
20 | * One point one
21 | * One point two
22 |
23 | 1. One
24 | 1. One point one
25 | 2. One point two
26 |
27 | * 1
28 | * 2
29 | * 2.1
30 | * 2.2
31 | * 2.2.1
32 | * 2.2.2
33 | * 2.2.3
34 | * 3
35 |
36 | 1. 1
37 | 2. 2
38 | 1. 2.1
39 | 2. 2.2
40 | 1. 2.2.1
41 | 2. 2.2.2
42 | 3. 2.2.3
43 | 4. 3
44 |
45 | * First Thing
46 |
47 | Second Thing
48 | * Nested First Thing
49 |
50 | Nested Thing
51 |
52 | 1. First Thing
53 |
54 | Second Thing
55 | 1. Nested First Thing
56 |
57 | Nested Thing
58 |
59 | 2. Date:
60 |
61 | 20.02.2021
62 |
63 | 26\. Mai - 3. Juni
--------------------------------------------------------------------------------
/testdata/TestRealWorld/snippets/turndown_demo/goldmark.golden:
--------------------------------------------------------------------------------
1 |
Turndown Demo
2 |
This demonstrates turndown – an HTML to Markdown converter in JavaScript.
3 |
Usage
4 |
var turndownService = new TurndownService()
5 | console.log(
6 | turndownService.turndown('<h1>Hello world</h1>')
7 | )
8 |
9 |
10 |
It aims to be CommonMark
11 | compliant, and includes options to style the output. These options include:
12 |
13 |
headingStyle (setext or atx)
14 |
horizontalRule (*, -, or _)
15 |
bullet (*, -, or +)
16 |
codeBlockStyle (indented or fenced)
17 |
fence
18 |
emDelimiter (_ or *)
19 |
strongDelimiter (** or __)
20 |
linkStyle (inlined or referenced)
21 |
linkReferenceStyle (full, collapsed, or shortcut)
22 |
23 |
--------------------------------------------------------------------------------
/plugin/strikethrough.go:
--------------------------------------------------------------------------------
1 | package plugin
2 |
3 | import (
4 | "strings"
5 |
6 | md "github.com/JohannesKaufmann/html-to-markdown"
7 | "github.com/PuerkitoBio/goquery"
8 | )
9 |
10 | // Strikethrough converts ``, ``, and `` elements
11 | func Strikethrough(character string) md.Plugin {
12 | return func(c *md.Converter) []md.Rule {
13 | if character == "" {
14 | character = "~~"
15 | }
16 |
17 | return []md.Rule{
18 | {
19 | Filter: []string{"del", "s", "strike"},
20 | Replacement: func(content string, selec *goquery.Selection, opt *md.Options) *string {
21 | // trim spaces so that the following does NOT happen: `~ and cake~`
22 | content = strings.TrimSpace(content)
23 |
24 | content = character + content + character
25 |
26 | // always have a space to the side to recognize the delimiter
27 | content = md.AddSpaceIfNessesary(selec, content)
28 |
29 | return &content
30 | },
31 | },
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/testdata/TestCommonmark/keep_remove_tag/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Content
4 |
5 |
6 |
7 |
Content
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
21 |
22 |
23 |
24 |
25 |
28 |
29 |
30 |
31 |
35 |
36 |
37 |
38 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/testdata/TestCommonmark/list/output.dash.golden:
--------------------------------------------------------------------------------
1 | - Some Thing
2 | - Another Thing
3 |
4 | 1. First Thing
5 | 2. Second Thing
6 |
7 | 01. 1
8 | 02. 2
9 | 03. 3
10 | 04. 4
11 | 05. 5
12 | 06. 6
13 | 07. 7
14 | 08. 8
15 | 09. 9
16 | 10. 10
17 | 11. 11
18 | 12. 12
19 | 13. 13
20 | 14. 14
21 | 15. 15
22 | 19. 16
23 | 20. 17
24 | 21. 18
25 | 22. 19
26 | 23. 20
27 | 24. 
28 | 25. 22
29 |
30 | - Link:[example](https://example.com) works
31 | - Link:
32 | [example](https://example.com)
33 | works
34 |
35 |
36 | 1. First Thing
37 | - Some Thing
38 | - Another Thing
39 | 2. Second Thing
40 |
41 | - foo
42 | - bar
43 |
44 | - List items
45 | - Ending with
46 | - A space
47 |
48 | - Indent First Thing
49 |
50 | Second Thing
51 |
52 | - Third Thing
53 |
54 | \- Not List
55 |
56 | 1\. Not List 1. Not List
57 | 1\. Not List
58 |
59 | 1. A paragraph
60 | with two lines.
61 |
62 |
63 | ```
64 | indented code
65 | ```
66 |
67 |
68 |
69 | > A block quote.
--------------------------------------------------------------------------------
/testdata/TestCommonmark/list/output.plus.golden:
--------------------------------------------------------------------------------
1 | + Some Thing
2 | + Another Thing
3 |
4 | 1. First Thing
5 | 2. Second Thing
6 |
7 | 01. 1
8 | 02. 2
9 | 03. 3
10 | 04. 4
11 | 05. 5
12 | 06. 6
13 | 07. 7
14 | 08. 8
15 | 09. 9
16 | 10. 10
17 | 11. 11
18 | 12. 12
19 | 13. 13
20 | 14. 14
21 | 15. 15
22 | 19. 16
23 | 20. 17
24 | 21. 18
25 | 22. 19
26 | 23. 20
27 | 24. 
28 | 25. 22
29 |
30 | + Link:[example](https://example.com) works
31 | + Link:
32 | [example](https://example.com)
33 | works
34 |
35 |
36 | 1. First Thing
37 | + Some Thing
38 | + Another Thing
39 | 2. Second Thing
40 |
41 | + foo
42 | + bar
43 |
44 | + List items
45 | + Ending with
46 | + A space
47 |
48 | + Indent First Thing
49 |
50 | Second Thing
51 |
52 | + Third Thing
53 |
54 | \- Not List
55 |
56 | 1\. Not List 1. Not List
57 | 1\. Not List
58 |
59 | 1. A paragraph
60 | with two lines.
61 |
62 |
63 | ```
64 | indented code
65 | ```
66 |
67 |
68 |
69 | > A block quote.
--------------------------------------------------------------------------------
/testdata/TestCommonmark/list/output.asterisks.golden:
--------------------------------------------------------------------------------
1 | * Some Thing
2 | * Another Thing
3 |
4 | 1. First Thing
5 | 2. Second Thing
6 |
7 | 01. 1
8 | 02. 2
9 | 03. 3
10 | 04. 4
11 | 05. 5
12 | 06. 6
13 | 07. 7
14 | 08. 8
15 | 09. 9
16 | 10. 10
17 | 11. 11
18 | 12. 12
19 | 13. 13
20 | 14. 14
21 | 15. 15
22 | 19. 16
23 | 20. 17
24 | 21. 18
25 | 22. 19
26 | 23. 20
27 | 24. 
28 | 25. 22
29 |
30 | * Link:[example](https://example.com) works
31 | * Link:
32 | [example](https://example.com)
33 | works
34 |
35 |
36 | 1. First Thing
37 | * Some Thing
38 | * Another Thing
39 | 2. Second Thing
40 |
41 | * foo
42 | * bar
43 |
44 | * List items
45 | * Ending with
46 | * A space
47 |
48 | * Indent First Thing
49 |
50 | Second Thing
51 |
52 | * Third Thing
53 |
54 | \- Not List
55 |
56 | 1\. Not List 1. Not List
57 | 1\. Not List
58 |
59 | 1. A paragraph
60 | with two lines.
61 |
62 |
63 | ```
64 | indented code
65 | ```
66 |
67 |
68 |
69 | > A block quote.
--------------------------------------------------------------------------------
/testdata/TestCommonmark/p_tag/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Some Content
4 |
5 |
6 |
7 |
8 |
Text
9 |
Some Text
10 |
11 |
12 |
13 |
14 |
Some Content
15 |
16 |
17 |
18 |
19 |
jmap –histo[:live]
20 |
21 |
22 |
23 |
24 | Sometimes a struct field, function, type, or even a whole package becomes
25 |
26 |
27 | redundant or unnecessary, but must be kept for compatibility with existing
28 |
29 |
30 | programs.
31 |
32 |
33 | To signal that an identifier should not be used, add a paragraph to its doc
34 |
35 |
36 | comment that begins with "Deprecated:" followed by some information about the
37 |
38 |
39 | deprecation.
40 |
41 |
42 | There are a few examples in the standard library.
43 |
23 |
24 |
25 | Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Vestibulum id ligula porta felis euismod semper.
26 | More
27 |
28 |
29 |
--------------------------------------------------------------------------------
/testdata/TestCommonmark/image/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
31 |
32 |
33 |
34 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/testdata/TestCommonmark/link/output.inlined.golden:
--------------------------------------------------------------------------------
1 | [Simple Absolute Link](http://simple.org/)
2 |
3 | [Simple Relative Link](http://example.com/page.html)
4 |
5 | [Link with Space](http://space.org/)
6 |
7 | [Link with Title](http://title.org/ "Some Title")
8 |
9 | [Link with multiline Title](http://title.org/ "Some Long Title")
10 |
11 | [Broken Link](http://broken.com/test.html%5Cr)
12 |
13 | [First Text\
14 | \
15 | Second Text](http://multi.org/)
16 |
17 | - [First Text\
18 | \
19 | Second Text](http://list.org/)
20 |
21 | [GitHub](https://github.com "GitHub")
22 |
23 | [first top](http://first_under.com) [second below](http://second_under.com)
24 |
25 | [first left](http://first_next.com) [second right](http://second_next.com)
26 |
27 | Before [close](http://example_close.com) After
28 |
29 | [**Heading A** **Heading B**](http://example.com/page.html)
30 |
31 | [DIW-Chef zum Grünen-Programm "Vermögenssteuer ist aus wirtschaftlicher Sicht klug"](http://example.com/page.html "\"Vermögenssteuer ist aus wirtschaftlicher Sicht klug\"")
32 |
33 | [**Die App WDR aktuell begleitet Sie durch den Tag**\
34 | \
35 | Sie möchten eine App, die Sie so durch den Tag in NRW begleitet, dass Sie jederzeit mitreden können? Die App WDR aktuell bietet Ihnen dafür immer die passenden Nachrichten.\
36 | \| \
37 | **mehr**](http://example.com/nachrichten/wdr-aktuell-app-stores-100.html "Die App WDR aktuell begleitet Sie durch den Tag ")
--------------------------------------------------------------------------------
/testdata/TestCommonmark/heading/input.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/testdata/TestCommonmark/pre_code/output.indented.golden:
--------------------------------------------------------------------------------
1 | `last_30_days`
2 |
3 | ``with backtick (`)``
4 |
5 | ```with backtick (``)```
6 |
7 | `````here are three ``` here are four ```` here is one ` that's it`````
8 |
9 | `` `starting & ending with a backtick` ``
10 |
11 | Who ate the most donuts this week?
12 |
13 | ```foo+bar
14 | Jeff 15
15 | Sam 11
16 | Robin 6
17 | ```
18 |
19 | ```
20 | // Fprint formats using the default formats for its operands and writes to w.
21 | // Spaces are added between operands when neither is a string.
22 | // It returns the number of bytes written and any write error encountered.
23 | func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
24 | ```
25 |
26 | When `x = 3`, that means `x + 2 = 5`
27 |
28 | The `` tag is used to embed an image.
29 |
30 | The `` tag is used to embed an image.
31 |
32 | Two variables `A` `B`
33 |
34 | CSS: `
35 | body {
36 | color: yellow;
37 | font-size: 16px;
38 | }
39 | `
40 |
41 | CSS: `
42 | body {
43 | color: yellow;
44 | font-size: 16px;
45 | }
46 | `
47 |
48 | ````
49 | ```
50 | ````
51 |
52 | ```
53 | ~~~
54 | ```
55 |
56 | ```
57 |
58 | Some ~~~
59 | totally ~~~~~~ normal
60 | ~ code
61 |
62 | ```
63 |
64 | ```
65 |
66 | The tag is used to embed an image.
67 |
68 | The tag is used to embed an image.
69 |
70 | ```
71 |
72 | ```
73 |
74 |
75 |
76 |
77 |
78 | ```
--------------------------------------------------------------------------------
/testdata/TestCommonmark/pre_code/output.fenced_backtick.golden:
--------------------------------------------------------------------------------
1 | `last_30_days`
2 |
3 | ``with backtick (`)``
4 |
5 | ```with backtick (``)```
6 |
7 | `````here are three ``` here are four ```` here is one ` that's it`````
8 |
9 | `` `starting & ending with a backtick` ``
10 |
11 | Who ate the most donuts this week?
12 |
13 | ```foo+bar
14 | Jeff 15
15 | Sam 11
16 | Robin 6
17 | ```
18 |
19 | ```
20 | // Fprint formats using the default formats for its operands and writes to w.
21 | // Spaces are added between operands when neither is a string.
22 | // It returns the number of bytes written and any write error encountered.
23 | func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
24 | ```
25 |
26 | When `x = 3`, that means `x + 2 = 5`
27 |
28 | The `` tag is used to embed an image.
29 |
30 | The `` tag is used to embed an image.
31 |
32 | Two variables `A` `B`
33 |
34 | CSS: `
35 | body {
36 | color: yellow;
37 | font-size: 16px;
38 | }
39 | `
40 |
41 | CSS: `
42 | body {
43 | color: yellow;
44 | font-size: 16px;
45 | }
46 | `
47 |
48 | ````
49 | ```
50 | ````
51 |
52 | ```
53 | ~~~
54 | ```
55 |
56 | ```
57 |
58 | Some ~~~
59 | totally ~~~~~~ normal
60 | ~ code
61 |
62 | ```
63 |
64 | ```
65 |
66 | The tag is used to embed an image.
67 |
68 | The tag is used to embed an image.
69 |
70 | ```
71 |
72 | ```
73 |
74 |
75 |
76 |
77 |
78 | ```
--------------------------------------------------------------------------------
/testdata/TestCommonmark/pre_code/output.fenced_tilde.golden:
--------------------------------------------------------------------------------
1 | `last_30_days`
2 |
3 | ``with backtick (`)``
4 |
5 | ```with backtick (``)```
6 |
7 | `````here are three ``` here are four ```` here is one ` that's it`````
8 |
9 | `` `starting & ending with a backtick` ``
10 |
11 | Who ate the most donuts this week?
12 |
13 | ~~~foo+bar
14 | Jeff 15
15 | Sam 11
16 | Robin 6
17 | ~~~
18 |
19 | ~~~
20 | // Fprint formats using the default formats for its operands and writes to w.
21 | // Spaces are added between operands when neither is a string.
22 | // It returns the number of bytes written and any write error encountered.
23 | func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
24 | ~~~
25 |
26 | When `x = 3`, that means `x + 2 = 5`
27 |
28 | The `` tag is used to embed an image.
29 |
30 | The `` tag is used to embed an image.
31 |
32 | Two variables `A` `B`
33 |
34 | CSS: `
35 | body {
36 | color: yellow;
37 | font-size: 16px;
38 | }
39 | `
40 |
41 | CSS: `
42 | body {
43 | color: yellow;
44 | font-size: 16px;
45 | }
46 | `
47 |
48 | ~~~
49 | ```
50 | ~~~
51 |
52 | ~~~~
53 | ~~~
54 | ~~~~
55 |
56 | ~~~~~~~
57 |
58 | Some ~~~
59 | totally ~~~~~~ normal
60 | ~ code
61 |
62 | ~~~~~~~
63 |
64 | ~~~
65 |
66 | The tag is used to embed an image.
67 |
68 | The tag is used to embed an image.
69 |
70 | ~~~
71 |
72 | ~~~
73 |
74 |
75 |
76 |
77 |
78 | ~~~
--------------------------------------------------------------------------------
/testdata/TestRealWorld/golang.org/output.default.golden:
--------------------------------------------------------------------------------
1 | The Go Programming Language
2 |
3 | ...
4 |
5 | [The Go Programming Language](http://golang.org/)
6 |
7 | [Go](http://golang.org/)
8 |
9 | ▽
10 |
11 | [Documents](http://golang.org/doc/) [Packages](http://golang.org/pkg/) [The Project](http://golang.org/project/) [Help](http://golang.org/help/) [Blog](http://golang.org/blog/) [Play](http://play.golang.org/ "Show Go Playground") submit search
12 |
13 | RunFormatShare
14 |
15 | Pop-out
16 |
17 | Try Go
18 |
19 | ```
20 | Hello, 世界
21 |
22 | ```
23 |
24 | RunShare [Tour](http://tour.golang.org/ "Learn Go from your browser")
25 |
26 | Hello, World!Conway's Game of LifeFibonacci ClosurePeano IntegersConcurrent piConcurrent Prime SievePeg Solitaire SolverTree Comparison
27 |
28 | Go is an open source programming language that makes it easy to build
29 | simple, reliable, and efficient software.
30 |
31 | [Download Go\
32 | Binary distributions available for\
33 | \
34 | Linux, Mac OS X, Windows, and more.](http://golang.org/dl/)
35 |
36 | Featured video
37 |
38 | Featured articles
39 |
40 | [Read more](http://blog.golang.org/)
41 |
42 | Build version go1.10.2.
43 |
44 | Except as [noted](https://developers.google.com/site-policies#restrictions),
45 | the content of this page is licensed under the
46 | Creative Commons Attribution 3.0 License,
47 | and code is licensed under a [BSD license](http://golang.org/LICENSE).
48 |
49 | [Terms of Service](http://golang.org/doc/tos.html) \|
50 | [Privacy Policy](http://www.google.com/intl/en/policies/privacy/)
--------------------------------------------------------------------------------
/plugin/confluence_code_block.go:
--------------------------------------------------------------------------------
1 | package plugin
2 |
3 | import (
4 | "fmt"
5 | "strings"
6 |
7 | md "github.com/JohannesKaufmann/html-to-markdown"
8 | "github.com/PuerkitoBio/goquery"
9 | )
10 |
11 | // ConfluenceCodeBlock converts `` elements that are used in Atlassian’s Wiki “Confluence”.
12 | // [Contributed by @Skarlso]
13 | func ConfluenceCodeBlock() md.Plugin {
14 | return func(c *md.Converter) []md.Rule {
15 | character := "```"
16 | return []md.Rule{
17 | {
18 | Filter: []string{"ac:structured-macro"},
19 | Replacement: func(content string, selec *goquery.Selection, opt *md.Options) *string {
20 | for _, node := range selec.Nodes {
21 | if node.Data == "ac:structured-macro" {
22 | // node's last child -> . We don't want to filter on that
23 | // because we would end up with structured-macro around us.
24 | // ac:plain-text-body's last child is [CDATA which has the actual content we are looking for.
25 | data := strings.TrimPrefix(node.LastChild.LastChild.Data, "[CDATA[")
26 | data = strings.TrimSuffix(data, "]]")
27 | // content, if set, will contain the language that has been set in the field.
28 | var language string
29 | if content != "" {
30 | language = content
31 | }
32 | formatted := fmt.Sprintf("%s%s\n%s\n%s", character, language, data, character)
33 | return md.String(formatted)
34 | }
35 | }
36 | return md.String(character + content + character)
37 | },
38 | },
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/examples/add_rules/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | "strings"
7 |
8 | md "github.com/JohannesKaufmann/html-to-markdown"
9 | "github.com/PuerkitoBio/goquery"
10 | )
11 |
12 | func main() {
13 | html := `Good soundtrack and cake.`
14 | // -> `Good soundtrack ~~and cake~~.`
15 |
16 | /*
17 | We want to add a rule when a `span` tag has a class of `bb_strike`.
18 | Have a look at `plugin/strikethrough.go` to see how it is implemented normally.
19 | */
20 | strikethrough := md.Rule{
21 | Filter: []string{"span"},
22 | Replacement: func(content string, selec *goquery.Selection, opt *md.Options) *string {
23 | // If the span element has not the classname `bb_strike` return nil.
24 | // That way the next rules will apply. In this case the commonmark rules.
25 | // -> return nil -> next rule applies
26 | if !selec.HasClass("bb_strike") {
27 | return nil
28 | }
29 |
30 | // Trim spaces so that the following does NOT happen: `~ and cake~`.
31 | // Because of the space it is not recognized as strikethrough.
32 | // -> trim spaces at begin&end of string when inside strong/italic/...
33 | content = strings.TrimSpace(content)
34 | return md.String("~~" + content + "~~")
35 | },
36 | }
37 |
38 | conv := md.NewConverter("", true, nil)
39 | conv.AddRules(strikethrough)
40 | // -> add 1+ rules to the converter. the last added will be used first.
41 |
42 | markdown, err := conv.ConvertString(html)
43 | if err != nil {
44 | log.Fatal(err)
45 | }
46 |
47 | fmt.Printf("\n\nmarkdown:'%s'\n", markdown)
48 | }
49 |
--------------------------------------------------------------------------------
/testdata/TestRealWorld/snippets/nav_nested_list/output.default.golden:
--------------------------------------------------------------------------------
1 | - [Startseite](http://example.com/ "Startseite")
2 | - [Die Gruppe](http://example.com/die-gruppe/unsere-unternehmen/ "Die Gruppe") - [Unsere Unternehmen](http://example.com/die-gruppe/unsere-unternehmen/ "Unsere Unternehmen")
3 | - [Unternehmenshistorie](http://example.com/die-gruppe/unternehmenshistorie/ "Unternehmenshistorie")
4 | - [Standortportraits](http://example.com/die-gruppe/standortportraits/ "Standortportraits")
5 | - [Unsere Marken](http://example.com/die-gruppe/unsere-marken/ "Unsere Marken")
6 | - [Kontakt](http://example.com/die-gruppe/kontakt/ "Kontakt")
7 | - [Medien](http://example.com/medien/aktuelle-meldungen/ "Medien") - [Aktuelle Meldungen](http://example.com/medien/aktuelle-meldungen/ "Aktuelle Meldungen")
8 | - [Pressearchiv](http://example.com/medien/pressearchiv/ "Pressearchiv")
9 | - [Pressekontakt](http://example.com/medien/pressekontakt/ "Pressekontakt")
10 | - [Einblicke](http://example.com/medien/einblicke/ "Einblicke")
11 | - [Karriere](http://example.com/karriere/ "Karriere") - [Video-Einblicke](http://example.com/karriere/video-einblicke/ "Video-Einblicke")
12 | - [Stellenangebote](https://career5.successfactors.eu/career?company=mllerservi&site=VjItNGdGZlNGSEJEYTVJSVRUaXp4N1E4Zz09 "Stellenangebote")
13 | - [Erlebnisberichte](http://example.com/karriere/erlebnisberichte/ "Erlebnisberichte")
14 | - [Traineeprogramm](http://example.com/karriere/traineeprogramm/ "Traineeprogramm")
15 | - [Termine](http://example.com/karriere/termine/ "Termine")
16 | - [News](http://example.com/karriere/news/ "News")
--------------------------------------------------------------------------------
/plugin/frontmatter.go:
--------------------------------------------------------------------------------
1 | package plugin
2 |
3 | import (
4 | "fmt"
5 |
6 | md "github.com/JohannesKaufmann/html-to-markdown"
7 | yaml "gopkg.in/yaml.v2"
8 | )
9 |
10 | // type frontMatterCallback func(selec *goquery.Selection) map[string]interface{}
11 | // TODO: automatically convert to formats (look at hugo)
12 |
13 | // EXPERIMENTALFrontMatter was an experiment to add certain data
14 | // from a callback function into the beginning of the file as frontmatter.
15 | // It not really working right now.
16 | //
17 | // If someone has a need for it, let me know what your use-case is. Then
18 | // I can create a plugin with a good interface.
19 | func EXPERIMENTALFrontMatter(format string) md.Plugin {
20 | return func(c *md.Converter) []md.Rule {
21 | data := make(map[string]interface{})
22 |
23 | d, err := yaml.Marshal(data)
24 | if err != nil {
25 | panic(err)
26 | }
27 |
28 | fmt.Println(string(d))
29 | /*
30 | add rule for `head`
31 | - get title
32 | - return AdvancedResult{ Header: formated_yaml }, skip
33 | -> added to head
34 | -> others rules can apply
35 |
36 | */
37 |
38 | title := "" // c.Find("head title").Text()
39 |
40 | var text string
41 | switch format {
42 | case "toml": // +++
43 | text = fmt.Sprintf(`
44 | +++
45 | title = "%s"
46 | +++
47 | `, title)
48 | case "yaml": // ---
49 | text = fmt.Sprintf(`
50 | ---
51 | title: %s
52 | ---
53 | `, title)
54 | case "json": // { }
55 | text = fmt.Sprintf(`
56 | {
57 | "title": "%s"
58 | }
59 | `, title)
60 | default:
61 | panic("unknown format")
62 | }
63 |
64 | _ = text
65 | // c.AddLeading(text)
66 | return nil
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/testdata/TestCommonmark/link/output.referenced_full.golden:
--------------------------------------------------------------------------------
1 | [Simple Absolute Link][1]
2 |
3 | [Simple Relative Link][2]
4 |
5 | [Link with Space][3]
6 |
7 | [Link with Title][4]
8 |
9 | [Link with multiline Title][5]
10 |
11 | [Broken Link][6]
12 |
13 | [First Text\
14 | \
15 | Second Text][7]
16 |
17 | - [First Text\
18 | \
19 | Second Text][8]
20 |
21 | [GitHub][9]
22 |
23 | [first top][10] [second below][11]
24 |
25 | [first left][12] [second right][13]
26 |
27 | Before [close][14] After
28 |
29 | [**Heading A** **Heading B**][15]
30 |
31 | [DIW-Chef zum Grünen-Programm "Vermögenssteuer ist aus wirtschaftlicher Sicht klug"][16]
32 |
33 | [**Die App WDR aktuell begleitet Sie durch den Tag**\
34 | \
35 | Sie möchten eine App, die Sie so durch den Tag in NRW begleitet, dass Sie jederzeit mitreden können? Die App WDR aktuell bietet Ihnen dafür immer die passenden Nachrichten.\
36 | \| \
37 | **mehr**][17]
38 |
39 | [1]: http://simple.org/
40 | [2]: http://example.com/page.html
41 | [3]: http://space.org/
42 | [4]: http://title.org/ "Some Title"
43 | [5]: http://title.org/ "Some Long Title"
44 | [6]: http://broken.com/test.html%5Cr
45 | [7]: http://multi.org/
46 | [8]: http://list.org/
47 | [9]: https://github.com "GitHub"
48 | [10]: http://first_under.com
49 | [11]: http://second_under.com
50 | [12]: http://first_next.com
51 | [13]: http://second_next.com
52 | [14]: http://example_close.com
53 | [15]: http://example.com/page.html
54 | [16]: http://example.com/page.html "\"Vermögenssteuer ist aus wirtschaftlicher Sicht klug\""
55 | [17]: http://example.com/nachrichten/wdr-aktuell-app-stores-100.html "Die App WDR aktuell begleitet Sie durch den Tag "
--------------------------------------------------------------------------------
/testdata/TestCommonmark/pre_code/goldmark.golden:
--------------------------------------------------------------------------------
1 |
last_30_days
2 |
with backtick (`)
3 |
with backtick (``)
4 |
here are three ``` here are four ```` here is one ` that's it
5 |
`starting & ending with a backtick`
6 |
Who ate the most donuts this week?
7 |
Jeff 15
8 | Sam 11
9 | Robin 6
10 |
11 |
// Fprint formats using the default formats for its operands and writes to w.
12 | // Spaces are added between operands when neither is a string.
13 | // It returns the number of bytes written and any write error encountered.
14 | func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
15 |
16 |
When x = 3, that means x + 2 = 5
17 |
The <img> tag is used to embed an image.
18 |
The <img/> tag is used to embed an image.
19 |
Two variables AB
20 |
CSS: body { color: yellow; font-size: 16px; }
21 |
CSS: body { color: yellow; font-size: 16px; }
22 |
```
23 |
24 |
~~~
25 |
26 |
27 | Some ~~~
28 | totally ~~~~~~ normal
29 | ~ code
30 |
31 |
32 |
33 | The <img> tag is used to embed an image.
34 |
35 | The <img/> tag is used to embed an image.
36 |
37 |
Except as noted,
26 | the content of this page is licensed under the
27 | Creative Commons Attribution 3.0 License,
28 | and code is licensed under a BSD license.
140 |
141 |
142 |
--------------------------------------------------------------------------------
/plugin/movefrontmatter.go:
--------------------------------------------------------------------------------
1 | package plugin
2 |
3 | import (
4 | "strings"
5 |
6 | md "github.com/JohannesKaufmann/html-to-markdown"
7 | "github.com/PuerkitoBio/goquery"
8 | )
9 |
10 | const moveFrontmatterAttr = "movefrontmatter"
11 |
12 | // EXPERIMENTALMoveFrontMatter moves a frontmatter block at the beginning
13 | // of the document to the top of the generated markdown block, without touching (and escaping) it.
14 | func EXPERIMENTALMoveFrontMatter(delimiters ...rune) md.Plugin {
15 | return func(c *md.Converter) []md.Rule {
16 | if len(delimiters) == 0 {
17 | delimiters = []rune{'+', '$', '-', '%'}
18 | }
19 |
20 | var delimitersList []string
21 | for _, c := range delimiters {
22 | delimitersList = append(delimitersList, strings.Repeat(string(c), 3))
23 | }
24 |
25 | isDelimiter := func(line string) bool {
26 | for _, delimiter := range delimitersList {
27 | if strings.HasPrefix(line, delimiter) {
28 | return true
29 | }
30 | }
31 | return false
32 | }
33 |
34 | c.Before(func(selec *goquery.Selection) {
35 | selec.Find("body").Contents().EachWithBreak(func(i int, s *goquery.Selection) bool {
36 | text := s.Text()
37 |
38 | // skip empty strings
39 | if strings.TrimSpace(text) == "" {
40 | return true
41 | }
42 |
43 | var frontmatter string
44 | var html string = text // if there is no frontmatter, keep the text
45 |
46 | lines := strings.Split(text, "\n")
47 | for i := 0; i < len(lines); i++ {
48 | if isDelimiter(lines[i]) {
49 | if i == 0 {
50 | continue
51 | }
52 |
53 | // split the frontmatter
54 | f := lines[:i+1]
55 | frontmatter = strings.Join(f, "\n")
56 |
57 | // and the html content AFTER the frontmatter
58 | h := lines[i+1:]
59 | html = strings.Join(h, "\n")
60 | break
61 | }
62 | }
63 |
64 | s.SetAttr(moveFrontmatterAttr, frontmatter)
65 | s.SetText(html)
66 |
67 | // the front matter must be the first thing in the file. So we break out of the loop
68 | return false
69 | })
70 | })
71 |
72 | return []md.Rule{
73 | {
74 | Filter: []string{"#text"},
75 | AdvancedReplacement: func(content string, selec *goquery.Selection, opt *md.Options) (md.AdvancedResult, bool) {
76 | frontmatter, exists := selec.Attr(moveFrontmatterAttr)
77 |
78 | if !exists {
79 | return md.AdvancedResult{}, true
80 | }
81 |
82 | return md.AdvancedResult{
83 | Header: frontmatter,
84 | Markdown: content,
85 | }, false
86 | },
87 | },
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/testdata/TestCommonmark/pre_code/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | last_30_days
4 |
5 |
6 |
7 |
8 | with backtick (`)
9 |
10 |
11 |
12 |
13 | with backtick (``)
14 |
15 |
16 |
17 |
18 | here are three ``` here are four ```` here is one ` that's it
19 |
20 |
21 |
22 |
23 | `starting & ending with a backtick`
24 |
25 |
26 |
27 |
28 |
29 |
Who ate the most donuts this week?
30 |
Jeff 15
31 | Sam 11
32 | Robin 6
33 |
34 |
35 |
36 |
37 |
// Fprint formats using the default formats for its operands and writes to w.
38 | // Spaces are added between operands when neither is a string.
39 | // It returns the number of bytes written and any write error encountered.
40 | func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
60 |
--------------------------------------------------------------------------------
/testdata/TestRealWorld/blog.golang.org/output.inlined.golden:
--------------------------------------------------------------------------------
1 | Godoc: documenting Go code - The Go Blog
2 |
3 | [The Go Programming Language](http://golang.org/)
4 |
5 | [Go](http://golang.org/)
6 |
7 | ▽
8 |
9 | [Documents](http://golang.org/doc/) [Packages](http://golang.org/pkg/) [The Project](http://golang.org/project/) [Help](http://golang.org/help/) [Blog](http://blog.golang.org/)submit search
10 |
11 | #### Next article
12 |
13 | [Introducing Gofix](http://blog.golang.org/introducing-gofix)
14 |
15 | #### Previous article
16 |
17 | [Gobs of data](http://blog.golang.org/gobs-of-data)
18 |
19 | #### Links
20 |
21 | - [golang.org](http://golang.org/)
22 | - [Install Go](http://golang.org/doc/install.html)
23 | - [A Tour of Go](http://tour.golang.org/)
24 | - [Go Documentation](http://golang.org/doc/)
25 | - [Go Mailing List](http://groups.google.com/group/golang-nuts)
26 | - [Go on Google+](http://plus.google.com/101406623878176903605)
27 | - [Go+ Community](http://plus.google.com/communities/114112804251407510571)
28 | - [Go on Twitter](http://twitter.com/golang)
29 |
30 | [Blog index](http://blog.golang.org/index)
31 |
32 | # [The Go Blog](http://blog.golang.org/)
33 |
34 | ### [Godoc: documenting Go code](http://blog.golang.org/godoc-documenting-go-code)
35 |
36 | 31 March 2011
37 |
38 | The Go project takes documentation seriously. Documentation is a huge part of making software accessible and maintainable.
39 | Of course it must be well-written and accurate, but it also must be easy to write and to maintain. Ideally, it
40 | should be coupled to the code itself so the documentation evolves along with the code. The easier it is for programmers
41 | to produce good documentation, the better for everyone.
42 |
43 |
44 | To that end, we have developed the
45 | [godoc](https://golang.org/cmd/godoc/) documentation tool. This article describes godoc's approach to documentation, and explains how
46 | you can use our conventions and tools to write good documentation for your own projects.
47 |
48 |
49 | Godoc parses Go source code - including comments - and produces documentation as HTML or plain text. The end result is documentation
50 | tightly coupled with the code it documents. For example, through godoc's web interface you can navigate from
51 | a function's
52 | [documentation](https://golang.org/pkg/strings/#HasPrefix) to its
53 | [implementation](https://golang.org/src/pkg/strings/strings.go#L493) with one click.
54 |
55 |
56 | Godoc is conceptually related to Python's
57 | [Docstring](http://www.python.org/dev/peps/pep-0257/) and Java's
58 | [Javadoc](http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-135444.html), but its design is simpler. The comments read by godoc are not language constructs (as with Docstring)
59 | nor must they have their own machine-readable syntax (as with Javadoc). Godoc comments are just good comments,
60 | the sort you would want to read even if godoc didn't exist.
61 |
62 |
63 | The convention is simple: to document a type, variable, constant, function, or even a package, write a regular comment directly
64 | preceding its declaration, with no intervening blank line. Godoc will then present that comment as text alongside
65 | the item it documents. For example, this is the documentation for the
66 | `fmt` package's
67 | [`Fprint`](https://golang.org/pkg/fmt/#Fprint) function:
68 |
69 |
70 | ```
71 | // Fprint formats using the default formats for its operands and writes to w.
72 | // Spaces are added between operands when neither is a string.
73 | // It returns the number of bytes written and any write error encountered.
74 | func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
75 | ```
76 |
77 | Notice this comment is a complete sentence that begins with the name of the element it describes. This important convention
78 | allows us to generate documentation in a variety of formats, from plain text to HTML to UNIX man pages, and makes
79 | it read better when tools truncate it for brevity, such as when they extract the first line or sentence.
80 |
81 |
82 | Comments on package declarations should provide general package documentation. These comments can be short, like the
83 | [`sort`](https://golang.org/pkg/sort/) package's brief description:
84 |
85 |
86 | ```
87 | // Package sort provides primitives for sorting slices and user-defined
88 | // collections.
89 | package sort
90 | ```
91 |
92 | They can also be detailed like the
93 | [gob package](https://golang.org/pkg/encoding/gob/)'s overview. That package uses another convention for packages that need large amounts of
94 | introductory documentation: the package comment is placed in its own file,
95 | [doc.go](https://golang.org/src/pkg/encoding/gob/doc.go), which contains only those comments and a package clause.
96 |
97 |
98 | When writing package comments of any size, keep in mind that their first sentence will appear in godoc's
99 | [package list](https://golang.org/pkg/).
100 |
101 |
102 | Comments that are not adjacent to a top-level declaration are omitted from godoc's output, with one notable exception.
103 | Top-level comments that begin with the word
104 | `"BUG(who)”` are recognized as known bugs, and included in the "Bugs” section of the package documentation. The "who”
105 | part should be the user name of someone who could provide more information. For example, this is a known issue
106 | from the
107 | [bytes package](https://golang.org/pkg/bytes/#pkg-note-BUG):
108 |
109 |
110 | ```
111 | // BUG(r): The rule Title uses for word boundaries does not handle Unicode punctuation properly.
112 | ```
113 |
114 | Sometimes a struct field, function, type, or even a whole package becomes redundant or unnecessary, but must be kept for
115 | compatibility with existing programs. To signal that an identifier should not be used, add a paragraph to its
116 | doc comment that begins with "Deprecated:" followed by some information about the deprecation. There
117 | are a few examples
118 | [in the standard library](https://golang.org/search?q=Deprecated:).
119 |
120 |
121 | There are a few formatting rules that Godoc uses when converting comments to HTML:
122 |
123 |
124 | - Subsequent lines of text are considered part of the same paragraph; you must leave a blank line to separate paragraphs.
125 |
126 | - Pre-formatted text must be indented relative to the surrounding comment text (see gob's
127 | [doc.go](https://golang.org/src/pkg/encoding/gob/doc.go) for an example).
128 |
129 | - URLs will be converted to HTML links; no special markup is necessary.
130 |
131 | Note that none of these rules requires you to do anything out of the ordinary.
132 |
133 |
134 | In fact, the best thing about godoc's minimal approach is how easy it is to use. As a result, a lot of Go code, including
135 | all of the standard library, already follows the conventions.
136 |
137 |
138 | Your own code can present good documentation just by having comments as described above. Any Go packages installed inside
139 | `$GOROOT/src/pkg` and any
140 | `GOPATH` work spaces will already be accessible via godoc's command-line and HTTP interfaces, and you can specify
141 | additional paths for indexing via the
142 | `-path` flag or just by running
143 | `"godoc ."` in the source directory. See the
144 | [godoc documentation](https://golang.org/cmd/godoc/) for more details.
145 |
146 |
147 | By Andrew Gerrand
148 |
149 | ## Related articles
150 |
151 | - [HTTP/2 Server Push](http://blog.golang.org/h2push)
152 | - [Introducing HTTP Tracing](http://blog.golang.org/http-tracing)
153 | - [Testable Examples in Go](http://blog.golang.org/examples)
154 | - [Generating code](http://blog.golang.org/generate)
155 | - [Introducing the Go Race Detector](http://blog.golang.org/race-detector)
156 | - [Go maps in action](http://blog.golang.org/go-maps-in-action)
157 | - [go fmt your code](http://blog.golang.org/go-fmt-your-code)
158 | - [Organizing Go code](http://blog.golang.org/organizing-go-code)
159 | - [Debugging Go programs with the GNU Debugger](http://blog.golang.org/debugging-go-programs-with-gnu-debugger)
160 | - [The Go image/draw package](http://blog.golang.org/go-imagedraw-package)
161 | - [The Go image package](http://blog.golang.org/go-image-package)
162 | - [The Laws of Reflection](http://blog.golang.org/laws-of-reflection)
163 | - [Error handling and Go](http://blog.golang.org/error-handling-and-go)
164 | - ["First Class Functions in Go"](http://blog.golang.org/first-class-functions-in-go-and-new-go)
165 | - [Profiling Go Programs](http://blog.golang.org/profiling-go-programs)
166 | - [A GIF decoder: an exercise in Go interfaces](http://blog.golang.org/gif-decoder-exercise-in-go-interfaces)
167 | - [Introducing Gofix](http://blog.golang.org/introducing-gofix)
168 | - [Gobs of data](http://blog.golang.org/gobs-of-data)
169 | - [C? Go? Cgo!](http://blog.golang.org/c-go-cgo)
170 | - [JSON and Go](http://blog.golang.org/json-and-go)
171 | - [Go Slices: usage and internals](http://blog.golang.org/go-slices-usage-and-internals)
172 | - [Go Concurrency Patterns: Timing out, moving on](http://blog.golang.org/go-concurrency-patterns-timing-out-and)
173 | - [Defer, Panic, and Recover](http://blog.golang.org/defer-panic-and-recover)
174 | - [Share Memory By Communicating](http://blog.golang.org/share-memory-by-communicating)
175 | - [JSON-RPC: a tale of interfaces](http://blog.golang.org/json-rpc-tale-of-interfaces)
176 |
177 | Except as
178 | [noted](https://developers.google.com/site-policies#restrictions), the content of this page is licensed under the Creative Commons Attribution 3.0 License,
179 |
180 |
181 | and code is licensed under a
182 | [BSD license](http://golang.org/LICENSE).
183 |
184 |
185 | [Terms of Service](http://golang.org/doc/tos.html) \|
186 | [Privacy Policy](http://www.google.com/intl/en/policies/privacy/) \|
187 | [View the source code](https://go.googlesource.com/blog/)
--------------------------------------------------------------------------------
/testdata/TestRealWorld/blog.golang.org/output.emphasis_asterisks.golden:
--------------------------------------------------------------------------------
1 | Godoc: documenting Go code - The Go Blog
2 |
3 | [The Go Programming Language](http://golang.org/)
4 |
5 | [Go](http://golang.org/)
6 |
7 | ▽
8 |
9 | [Documents](http://golang.org/doc/) [Packages](http://golang.org/pkg/) [The Project](http://golang.org/project/) [Help](http://golang.org/help/) [Blog](http://blog.golang.org/)submit search
10 |
11 | #### Next article
12 |
13 | [Introducing Gofix](http://blog.golang.org/introducing-gofix)
14 |
15 | #### Previous article
16 |
17 | [Gobs of data](http://blog.golang.org/gobs-of-data)
18 |
19 | #### Links
20 |
21 | - [golang.org](http://golang.org/)
22 | - [Install Go](http://golang.org/doc/install.html)
23 | - [A Tour of Go](http://tour.golang.org/)
24 | - [Go Documentation](http://golang.org/doc/)
25 | - [Go Mailing List](http://groups.google.com/group/golang-nuts)
26 | - [Go on Google+](http://plus.google.com/101406623878176903605)
27 | - [Go+ Community](http://plus.google.com/communities/114112804251407510571)
28 | - [Go on Twitter](http://twitter.com/golang)
29 |
30 | [Blog index](http://blog.golang.org/index)
31 |
32 | # [The Go Blog](http://blog.golang.org/)
33 |
34 | ### [Godoc: documenting Go code](http://blog.golang.org/godoc-documenting-go-code)
35 |
36 | 31 March 2011
37 |
38 | The Go project takes documentation seriously. Documentation is a huge part of making software accessible and maintainable.
39 | Of course it must be well-written and accurate, but it also must be easy to write and to maintain. Ideally, it
40 | should be coupled to the code itself so the documentation evolves along with the code. The easier it is for programmers
41 | to produce good documentation, the better for everyone.
42 |
43 |
44 | To that end, we have developed the
45 | [godoc](https://golang.org/cmd/godoc/) documentation tool. This article describes godoc's approach to documentation, and explains how
46 | you can use our conventions and tools to write good documentation for your own projects.
47 |
48 |
49 | Godoc parses Go source code - including comments - and produces documentation as HTML or plain text. The end result is documentation
50 | tightly coupled with the code it documents. For example, through godoc's web interface you can navigate from
51 | a function's
52 | [documentation](https://golang.org/pkg/strings/#HasPrefix) to its
53 | [implementation](https://golang.org/src/pkg/strings/strings.go#L493) with one click.
54 |
55 |
56 | Godoc is conceptually related to Python's
57 | [Docstring](http://www.python.org/dev/peps/pep-0257/) and Java's
58 | [Javadoc](http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-135444.html), but its design is simpler. The comments read by godoc are not language constructs (as with Docstring)
59 | nor must they have their own machine-readable syntax (as with Javadoc). Godoc comments are just good comments,
60 | the sort you would want to read even if godoc didn't exist.
61 |
62 |
63 | The convention is simple: to document a type, variable, constant, function, or even a package, write a regular comment directly
64 | preceding its declaration, with no intervening blank line. Godoc will then present that comment as text alongside
65 | the item it documents. For example, this is the documentation for the
66 | `fmt` package's
67 | [`Fprint`](https://golang.org/pkg/fmt/#Fprint) function:
68 |
69 |
70 | ```
71 | // Fprint formats using the default formats for its operands and writes to w.
72 | // Spaces are added between operands when neither is a string.
73 | // It returns the number of bytes written and any write error encountered.
74 | func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
75 | ```
76 |
77 | Notice this comment is a complete sentence that begins with the name of the element it describes. This important convention
78 | allows us to generate documentation in a variety of formats, from plain text to HTML to UNIX man pages, and makes
79 | it read better when tools truncate it for brevity, such as when they extract the first line or sentence.
80 |
81 |
82 | Comments on package declarations should provide general package documentation. These comments can be short, like the
83 | [`sort`](https://golang.org/pkg/sort/) package's brief description:
84 |
85 |
86 | ```
87 | // Package sort provides primitives for sorting slices and user-defined
88 | // collections.
89 | package sort
90 | ```
91 |
92 | They can also be detailed like the
93 | [gob package](https://golang.org/pkg/encoding/gob/)'s overview. That package uses another convention for packages that need large amounts of
94 | introductory documentation: the package comment is placed in its own file,
95 | [doc.go](https://golang.org/src/pkg/encoding/gob/doc.go), which contains only those comments and a package clause.
96 |
97 |
98 | When writing package comments of any size, keep in mind that their first sentence will appear in godoc's
99 | [package list](https://golang.org/pkg/).
100 |
101 |
102 | Comments that are not adjacent to a top-level declaration are omitted from godoc's output, with one notable exception.
103 | Top-level comments that begin with the word
104 | `"BUG(who)”` are recognized as known bugs, and included in the "Bugs” section of the package documentation. The "who”
105 | part should be the user name of someone who could provide more information. For example, this is a known issue
106 | from the
107 | [bytes package](https://golang.org/pkg/bytes/#pkg-note-BUG):
108 |
109 |
110 | ```
111 | // BUG(r): The rule Title uses for word boundaries does not handle Unicode punctuation properly.
112 | ```
113 |
114 | Sometimes a struct field, function, type, or even a whole package becomes redundant or unnecessary, but must be kept for
115 | compatibility with existing programs. To signal that an identifier should not be used, add a paragraph to its
116 | doc comment that begins with "Deprecated:" followed by some information about the deprecation. There
117 | are a few examples
118 | [in the standard library](https://golang.org/search?q=Deprecated:).
119 |
120 |
121 | There are a few formatting rules that Godoc uses when converting comments to HTML:
122 |
123 |
124 | - Subsequent lines of text are considered part of the same paragraph; you must leave a blank line to separate paragraphs.
125 |
126 | - Pre-formatted text must be indented relative to the surrounding comment text (see gob's
127 | [doc.go](https://golang.org/src/pkg/encoding/gob/doc.go) for an example).
128 |
129 | - URLs will be converted to HTML links; no special markup is necessary.
130 |
131 | Note that none of these rules requires you to do anything out of the ordinary.
132 |
133 |
134 | In fact, the best thing about godoc's minimal approach is how easy it is to use. As a result, a lot of Go code, including
135 | all of the standard library, already follows the conventions.
136 |
137 |
138 | Your own code can present good documentation just by having comments as described above. Any Go packages installed inside
139 | `$GOROOT/src/pkg` and any
140 | `GOPATH` work spaces will already be accessible via godoc's command-line and HTTP interfaces, and you can specify
141 | additional paths for indexing via the
142 | `-path` flag or just by running
143 | `"godoc ."` in the source directory. See the
144 | [godoc documentation](https://golang.org/cmd/godoc/) for more details.
145 |
146 |
147 | By Andrew Gerrand
148 |
149 | ## Related articles
150 |
151 | - [HTTP/2 Server Push](http://blog.golang.org/h2push)
152 | - [Introducing HTTP Tracing](http://blog.golang.org/http-tracing)
153 | - [Testable Examples in Go](http://blog.golang.org/examples)
154 | - [Generating code](http://blog.golang.org/generate)
155 | - [Introducing the Go Race Detector](http://blog.golang.org/race-detector)
156 | - [Go maps in action](http://blog.golang.org/go-maps-in-action)
157 | - [go fmt your code](http://blog.golang.org/go-fmt-your-code)
158 | - [Organizing Go code](http://blog.golang.org/organizing-go-code)
159 | - [Debugging Go programs with the GNU Debugger](http://blog.golang.org/debugging-go-programs-with-gnu-debugger)
160 | - [The Go image/draw package](http://blog.golang.org/go-imagedraw-package)
161 | - [The Go image package](http://blog.golang.org/go-image-package)
162 | - [The Laws of Reflection](http://blog.golang.org/laws-of-reflection)
163 | - [Error handling and Go](http://blog.golang.org/error-handling-and-go)
164 | - ["First Class Functions in Go"](http://blog.golang.org/first-class-functions-in-go-and-new-go)
165 | - [Profiling Go Programs](http://blog.golang.org/profiling-go-programs)
166 | - [A GIF decoder: an exercise in Go interfaces](http://blog.golang.org/gif-decoder-exercise-in-go-interfaces)
167 | - [Introducing Gofix](http://blog.golang.org/introducing-gofix)
168 | - [Gobs of data](http://blog.golang.org/gobs-of-data)
169 | - [C? Go? Cgo!](http://blog.golang.org/c-go-cgo)
170 | - [JSON and Go](http://blog.golang.org/json-and-go)
171 | - [Go Slices: usage and internals](http://blog.golang.org/go-slices-usage-and-internals)
172 | - [Go Concurrency Patterns: Timing out, moving on](http://blog.golang.org/go-concurrency-patterns-timing-out-and)
173 | - [Defer, Panic, and Recover](http://blog.golang.org/defer-panic-and-recover)
174 | - [Share Memory By Communicating](http://blog.golang.org/share-memory-by-communicating)
175 | - [JSON-RPC: a tale of interfaces](http://blog.golang.org/json-rpc-tale-of-interfaces)
176 |
177 | Except as
178 | [noted](https://developers.google.com/site-policies#restrictions), the content of this page is licensed under the Creative Commons Attribution 3.0 License,
179 |
180 |
181 | and code is licensed under a
182 | [BSD license](http://golang.org/LICENSE).
183 |
184 |
185 | [Terms of Service](http://golang.org/doc/tos.html) \|
186 | [Privacy Policy](http://www.google.com/intl/en/policies/privacy/) \|
187 | [View the source code](https://go.googlesource.com/blog/)
--------------------------------------------------------------------------------
/testdata/TestRealWorld/blog.golang.org/output.emphasis_underscores.golden:
--------------------------------------------------------------------------------
1 | Godoc: documenting Go code - The Go Blog
2 |
3 | [The Go Programming Language](http://golang.org/)
4 |
5 | [Go](http://golang.org/)
6 |
7 | ▽
8 |
9 | [Documents](http://golang.org/doc/) [Packages](http://golang.org/pkg/) [The Project](http://golang.org/project/) [Help](http://golang.org/help/) [Blog](http://blog.golang.org/)submit search
10 |
11 | #### Next article
12 |
13 | [Introducing Gofix](http://blog.golang.org/introducing-gofix)
14 |
15 | #### Previous article
16 |
17 | [Gobs of data](http://blog.golang.org/gobs-of-data)
18 |
19 | #### Links
20 |
21 | - [golang.org](http://golang.org/)
22 | - [Install Go](http://golang.org/doc/install.html)
23 | - [A Tour of Go](http://tour.golang.org/)
24 | - [Go Documentation](http://golang.org/doc/)
25 | - [Go Mailing List](http://groups.google.com/group/golang-nuts)
26 | - [Go on Google+](http://plus.google.com/101406623878176903605)
27 | - [Go+ Community](http://plus.google.com/communities/114112804251407510571)
28 | - [Go on Twitter](http://twitter.com/golang)
29 |
30 | [Blog index](http://blog.golang.org/index)
31 |
32 | # [The Go Blog](http://blog.golang.org/)
33 |
34 | ### [Godoc: documenting Go code](http://blog.golang.org/godoc-documenting-go-code)
35 |
36 | 31 March 2011
37 |
38 | The Go project takes documentation seriously. Documentation is a huge part of making software accessible and maintainable.
39 | Of course it must be well-written and accurate, but it also must be easy to write and to maintain. Ideally, it
40 | should be coupled to the code itself so the documentation evolves along with the code. The easier it is for programmers
41 | to produce good documentation, the better for everyone.
42 |
43 |
44 | To that end, we have developed the
45 | [godoc](https://golang.org/cmd/godoc/) documentation tool. This article describes godoc's approach to documentation, and explains how
46 | you can use our conventions and tools to write good documentation for your own projects.
47 |
48 |
49 | Godoc parses Go source code - including comments - and produces documentation as HTML or plain text. The end result is documentation
50 | tightly coupled with the code it documents. For example, through godoc's web interface you can navigate from
51 | a function's
52 | [documentation](https://golang.org/pkg/strings/#HasPrefix) to its
53 | [implementation](https://golang.org/src/pkg/strings/strings.go#L493) with one click.
54 |
55 |
56 | Godoc is conceptually related to Python's
57 | [Docstring](http://www.python.org/dev/peps/pep-0257/) and Java's
58 | [Javadoc](http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-135444.html), but its design is simpler. The comments read by godoc are not language constructs (as with Docstring)
59 | nor must they have their own machine-readable syntax (as with Javadoc). Godoc comments are just good comments,
60 | the sort you would want to read even if godoc didn't exist.
61 |
62 |
63 | The convention is simple: to document a type, variable, constant, function, or even a package, write a regular comment directly
64 | preceding its declaration, with no intervening blank line. Godoc will then present that comment as text alongside
65 | the item it documents. For example, this is the documentation for the
66 | `fmt` package's
67 | [`Fprint`](https://golang.org/pkg/fmt/#Fprint) function:
68 |
69 |
70 | ```
71 | // Fprint formats using the default formats for its operands and writes to w.
72 | // Spaces are added between operands when neither is a string.
73 | // It returns the number of bytes written and any write error encountered.
74 | func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
75 | ```
76 |
77 | Notice this comment is a complete sentence that begins with the name of the element it describes. This important convention
78 | allows us to generate documentation in a variety of formats, from plain text to HTML to UNIX man pages, and makes
79 | it read better when tools truncate it for brevity, such as when they extract the first line or sentence.
80 |
81 |
82 | Comments on package declarations should provide general package documentation. These comments can be short, like the
83 | [`sort`](https://golang.org/pkg/sort/) package's brief description:
84 |
85 |
86 | ```
87 | // Package sort provides primitives for sorting slices and user-defined
88 | // collections.
89 | package sort
90 | ```
91 |
92 | They can also be detailed like the
93 | [gob package](https://golang.org/pkg/encoding/gob/)'s overview. That package uses another convention for packages that need large amounts of
94 | introductory documentation: the package comment is placed in its own file,
95 | [doc.go](https://golang.org/src/pkg/encoding/gob/doc.go), which contains only those comments and a package clause.
96 |
97 |
98 | When writing package comments of any size, keep in mind that their first sentence will appear in godoc's
99 | [package list](https://golang.org/pkg/).
100 |
101 |
102 | Comments that are not adjacent to a top-level declaration are omitted from godoc's output, with one notable exception.
103 | Top-level comments that begin with the word
104 | `"BUG(who)”` are recognized as known bugs, and included in the "Bugs” section of the package documentation. The "who”
105 | part should be the user name of someone who could provide more information. For example, this is a known issue
106 | from the
107 | [bytes package](https://golang.org/pkg/bytes/#pkg-note-BUG):
108 |
109 |
110 | ```
111 | // BUG(r): The rule Title uses for word boundaries does not handle Unicode punctuation properly.
112 | ```
113 |
114 | Sometimes a struct field, function, type, or even a whole package becomes redundant or unnecessary, but must be kept for
115 | compatibility with existing programs. To signal that an identifier should not be used, add a paragraph to its
116 | doc comment that begins with "Deprecated:" followed by some information about the deprecation. There
117 | are a few examples
118 | [in the standard library](https://golang.org/search?q=Deprecated:).
119 |
120 |
121 | There are a few formatting rules that Godoc uses when converting comments to HTML:
122 |
123 |
124 | - Subsequent lines of text are considered part of the same paragraph; you must leave a blank line to separate paragraphs.
125 |
126 | - Pre-formatted text must be indented relative to the surrounding comment text (see gob's
127 | [doc.go](https://golang.org/src/pkg/encoding/gob/doc.go) for an example).
128 |
129 | - URLs will be converted to HTML links; no special markup is necessary.
130 |
131 | Note that none of these rules requires you to do anything out of the ordinary.
132 |
133 |
134 | In fact, the best thing about godoc's minimal approach is how easy it is to use. As a result, a lot of Go code, including
135 | all of the standard library, already follows the conventions.
136 |
137 |
138 | Your own code can present good documentation just by having comments as described above. Any Go packages installed inside
139 | `$GOROOT/src/pkg` and any
140 | `GOPATH` work spaces will already be accessible via godoc's command-line and HTTP interfaces, and you can specify
141 | additional paths for indexing via the
142 | `-path` flag or just by running
143 | `"godoc ."` in the source directory. See the
144 | [godoc documentation](https://golang.org/cmd/godoc/) for more details.
145 |
146 |
147 | By Andrew Gerrand
148 |
149 | ## Related articles
150 |
151 | - [HTTP/2 Server Push](http://blog.golang.org/h2push)
152 | - [Introducing HTTP Tracing](http://blog.golang.org/http-tracing)
153 | - [Testable Examples in Go](http://blog.golang.org/examples)
154 | - [Generating code](http://blog.golang.org/generate)
155 | - [Introducing the Go Race Detector](http://blog.golang.org/race-detector)
156 | - [Go maps in action](http://blog.golang.org/go-maps-in-action)
157 | - [go fmt your code](http://blog.golang.org/go-fmt-your-code)
158 | - [Organizing Go code](http://blog.golang.org/organizing-go-code)
159 | - [Debugging Go programs with the GNU Debugger](http://blog.golang.org/debugging-go-programs-with-gnu-debugger)
160 | - [The Go image/draw package](http://blog.golang.org/go-imagedraw-package)
161 | - [The Go image package](http://blog.golang.org/go-image-package)
162 | - [The Laws of Reflection](http://blog.golang.org/laws-of-reflection)
163 | - [Error handling and Go](http://blog.golang.org/error-handling-and-go)
164 | - ["First Class Functions in Go"](http://blog.golang.org/first-class-functions-in-go-and-new-go)
165 | - [Profiling Go Programs](http://blog.golang.org/profiling-go-programs)
166 | - [A GIF decoder: an exercise in Go interfaces](http://blog.golang.org/gif-decoder-exercise-in-go-interfaces)
167 | - [Introducing Gofix](http://blog.golang.org/introducing-gofix)
168 | - [Gobs of data](http://blog.golang.org/gobs-of-data)
169 | - [C? Go? Cgo!](http://blog.golang.org/c-go-cgo)
170 | - [JSON and Go](http://blog.golang.org/json-and-go)
171 | - [Go Slices: usage and internals](http://blog.golang.org/go-slices-usage-and-internals)
172 | - [Go Concurrency Patterns: Timing out, moving on](http://blog.golang.org/go-concurrency-patterns-timing-out-and)
173 | - [Defer, Panic, and Recover](http://blog.golang.org/defer-panic-and-recover)
174 | - [Share Memory By Communicating](http://blog.golang.org/share-memory-by-communicating)
175 | - [JSON-RPC: a tale of interfaces](http://blog.golang.org/json-rpc-tale-of-interfaces)
176 |
177 | Except as
178 | [noted](https://developers.google.com/site-policies#restrictions), the content of this page is licensed under the Creative Commons Attribution 3.0 License,
179 |
180 |
181 | and code is licensed under a
182 | [BSD license](http://golang.org/LICENSE).
183 |
184 |
185 | [Terms of Service](http://golang.org/doc/tos.html) \|
186 | [Privacy Policy](http://www.google.com/intl/en/policies/privacy/) \|
187 | [View the source code](https://go.googlesource.com/blog/)
--------------------------------------------------------------------------------