` elements that are used in Atlassian’s Wiki "Confluence". |
| ConfluenceAttachments | Converts `` elements. |
These are the plugins in other repositories:
| Name | Description |
| ---------------------------- | ------------------- |
| \[Plugin Name\]\(Your Link\) | A short description |
I you write a plugin, feel free to open a PR that adds your Plugin to this list.
## Writing Plugins
Have a look at the [plugin folder](/plugin) for a reference implementation. The most basic one is [Strikethrough](/plugin/strikethrough.go).
## Security
This library produces markdown that is readable and can be changed by humans.
Once you convert this markdown back to HTML (e.g. using [goldmark](https://github.com/yuin/goldmark) or [blackfriday](https://github.com/russross/blackfriday)) you need to be careful of malicious content.
This library does NOT sanitize untrusted content. Use an HTML sanitizer such as [bluemonday](https://github.com/microcosm-cc/bluemonday) before displaying the HTML in the browser.
## Other Methods
[Godoc](https://godoc.org/github.com/tomkosm/html-to-markdown)
### `func (c *Converter) Keep(tags ...string) *Converter`
Determines which elements are to be kept and rendered as HTML.
### `func (c *Converter) Remove(tags ...string) *Converter`
Determines which elements are to be removed altogether i.e. converted to an empty string.
## Escaping
Some characters have a special meaning in markdown. For example, the character "\*" can be used for lists, emphasis and dividers. By placing a backlash before that character (e.g. "\\\*") you can "escape" it. Then the character will render as a raw "\*" without the _"markdown meaning"_ applied.
But why is "escaping" even necessary?
```md
Paragraph 1
-
Paragraph 2
```
The markdown above doesn't seem that problematic. But "Paragraph 1" (with only one hyphen below) will be recognized as a _setext heading_.
```html
Paragraph 1
Paragraph 2
```
A well-placed backslash character would prevent that...
```md
Paragraph 1
\-
Paragraph 2
```
---
How to configure escaping? Depending on the `EscapeMode` option, the markdown output is going to be different.
```go
opt = &md.Options{
EscapeMode: "basic", // default
}
```
Lets try it out with this HTML input:
| | |
| -------- | ----------------------------------------------------- |
| input | `fake **bold** and real bold
` |
| | |
| | **With EscapeMode "basic"** |
| output | `fake \*\*bold\*\* and real **bold**` |
| rendered | fake \*\*bold\*\* and real **bold** |
| | |
| | **With EscapeMode "disabled"** |
| output | `fake **bold** and real **bold**` |
| rendered | fake **bold** and real **bold** |
With **basic** escaping, we get some escape characters (the backlash "\\") but it renders correctly.
With escaping **disabled**, the fake and real bold can't be distinguished in the markdown. That means it is both going to render as bold.
---
So now you know the purpose of escaping. However, if you encounter some content where the escaping breaks, you can manually disable it. But please also open an issue!
## Issues
If you find HTML snippets (or even full websites) that don't produce the expected results, please open an issue!
## Contributing & Testing
Please first discuss the change you wish to make, by opening an issue. I'm also happy to guide you to where a change is most likely needed.
_Note: The outside API should not change because of backwards compatibility..._
You don't have to be afraid of breaking the converter, since there are many "Golden File Tests":
Add your problematic HTML snippet to one of the `input.html` files in the `testdata` folder. Then run `go test -update` and have a look at which `.golden` files changed in GIT.
You can now change the internal logic and inspect what impact your change has by running `go test -update` again.
_Note: Before submitting your change as a PR, make sure that you run those tests and check the files into GIT..._
## Related Projects
- [turndown (js)](https://github.com/domchristie/turndown), a very good library written in javascript.
- [lunny/html2md](https://github.com/lunny/html2md), which is using [regex instead of goquery](https://stackoverflow.com/a/1732454). I came around a few edge case when using it (leaving some html comments, ...) so I wrote my own.
## License
This project is licensed under the terms of the MIT license.