Comments (2)
I'm unlikely to have time to implement a big change like that.
There's no support for markdown-inside-html. ast.HTMLBlock
is a leaf node which means there's no support for it to have children.
Not impossible but probably a big change and would require a parser flag as this is significantly different behavior.
from markdown.
This can be implemented as a parser hook + renderer hook.
package renderer
import (
"bytes"
"io"
"github.com/gomarkdown/markdown/ast"
)
type Details struct {
ast.Container
}
var details = []byte("<details>")
func ParserHook(data []byte) (ast.Node, []byte, int) {
if node, d, n := parseDetails(data); node != nil {
return node, d, n
}
return nil, nil, 0
}
func parseDetails(data []byte) (ast.Node, []byte, int) {
if !bytes.HasPrefix(data, sidenote) {
return nil, nil, 0
}
i := bytes.Index(data, details)
end := bytes.Index(data[i:], []byte("</details>"))
if end < 0 {
return nil, data, 0
}
end = end + i
res := &Details{}
return res, data[i:end], end + len([]byte("</details>"))
}
func renderDetails(w io.Writer, s *Details, entering bool) {
if entering {
io.WriteString(w, "<details>")
} else {
io.WriteString(w, "</details>")
}
}
func RenderHook(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
if leafNode, ok := node.(*Details); ok {
renderDetails(w, leafNode, entering)
return ast.GoToNext, true
}
return ast.GoToNext, false
}
There may be some mistakes here, but the idea should work. The keys is to abuse the order of parsing (the parser hook is evaluated before html blocks) and the second return value of parser hook (it is added as a child of the Details
container and will be parsed as a block).
This implies that you'll need to create a new struct
for html blocks that need to be parsed like this.
from markdown.
Related Issues (20)
- Implement support for inline element attributes HOT 2
- Parsing error when parsing nested bold+ital
- Parser panics when called `Parse` is called multiple times HOT 3
- image resize ? HOT 1
- No way to escape `$` MathJax blocks HOT 2
- А list followed by a header is parsed (or rendered?) the wrong way HOT 1
- Support for external code renderers HOT 1
- md.Renderer implementation status HOT 7
- link parsing does not work at all
- How to extend inline markdown parsing? HOT 5
- Dependabot security issue HOT 1
- Unexpected behaviour with Container.Content HOT 1
- Please tag an official v1.0.0 release.
- Question about list with tight option enabled HOT 4
- Brackets and parenthesis with space in between is parsed as Link HOT 2
- Stripping markdown HOT 6
- Disable mathjax by default? HOT 1
- MathML support
- Can't reuse parser or renderer HOT 1
- markdown.Parse cause garbled characters in some Chinese scenarios HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markdown.