Add RTL rendering support to Markdown (#24816)
Support RTL content in Markdown:

Example document:
https://try.gitea.io/silverwind/symlink-test/src/branch/master/bidi-text.md
Same on GitHub:
https://github.com/silverwind/symlink-test/blob/master/bidi-text.md
`dir=auto` enables a browser heuristic that sets the text direction
automatically. It is the only way to get automatic text direction.
Ref: https://codeberg.org/Codeberg/Community/issues/1021
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
1698c15cba
commit
32d9c47ec7
7 changed files with 23 additions and 5 deletions
|
@ -47,6 +47,12 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
|
|||
tocMode = rc.TOC
|
||||
}
|
||||
|
||||
applyElementDir := func(n ast.Node) {
|
||||
if markup.DefaultProcessorHelper.ElementDir != "" {
|
||||
n.SetAttributeString("dir", []byte(markup.DefaultProcessorHelper.ElementDir))
|
||||
}
|
||||
}
|
||||
|
||||
attentionMarkedBlockquotes := make(container.Set[*ast.Blockquote])
|
||||
_ = ast.Walk(node, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||
if !entering {
|
||||
|
@ -69,6 +75,9 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
|
|||
header.ID = util.BytesToReadOnlyString(id.([]byte))
|
||||
}
|
||||
tocList = append(tocList, header)
|
||||
applyElementDir(v)
|
||||
case *ast.Paragraph:
|
||||
applyElementDir(v)
|
||||
case *ast.Image:
|
||||
// Images need two things:
|
||||
//
|
||||
|
@ -171,6 +180,7 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
|
|||
v.AppendChild(v, newChild)
|
||||
}
|
||||
}
|
||||
applyElementDir(v)
|
||||
case *ast.Text:
|
||||
if v.SoftLineBreak() && !v.HardLineBreak() {
|
||||
renderMetas := pc.Get(renderMetasKey).(map[string]string)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue