Skip to content

Commit 7ee652d

Browse files
committed
Add RTL rendering support to Markdown
1 parent 1698c15 commit 7ee652d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

modules/markup/markdown/goldmark.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
6969
header.ID = util.BytesToReadOnlyString(id.([]byte))
7070
}
7171
tocList = append(tocList, header)
72+
v.SetAttributeString("dir", []byte("auto"))
73+
case *ast.Paragraph:
74+
v.SetAttributeString("dir", []byte("auto"))
7275
case *ast.Image:
7376
// Images need two things:
7477
//
@@ -171,6 +174,7 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
171174
v.AppendChild(v, newChild)
172175
}
173176
}
177+
v.SetAttributeString("dir", []byte("auto"))
174178
case *ast.Text:
175179
if v.SoftLineBreak() && !v.HardLineBreak() {
176180
renderMetas := pc.Get(renderMetasKey).(map[string]string)

modules/markup/sanitizer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ func createDefaultPolicy() *bluemonday.Policy {
102102
// Allow 'style' attribute on text elements.
103103
policy.AllowAttrs("style").OnElements("span", "p")
104104

105+
// Allow 'dir' attribute on elements that may contain rtl content.
106+
policy.AllowAttrs("dir").OnElements("span", "div", "p", "ul", "ol", "h1", "h2", "h3", "h4", "h5", "h6")
107+
105108
// Allow 'color' and 'background-color' properties for the style attribute on text elements.
106109
policy.AllowStyles("color", "background-color").OnElements("span", "p")
107110

0 commit comments

Comments
 (0)