-
Notifications
You must be signed in to change notification settings - Fork 17.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/present: "new" markdown syntax turns all sections into HTML #48841
Comments
alternatively, one could perhaps add a field to |
thinking a bit more on this issue, and as (AFAICT) the original something along the lines of: diff --git a/present/parse.go b/present/parse.go
index 4294ea5f..18c15fe9 100644
--- a/present/parse.go
+++ b/present/parse.go
@@ -273,6 +273,9 @@ func (l *Lines) nextNonEmpty() (text string, ok bool) {
type Context struct {
// ReadFile reads the file named by filename and returns the contents.
ReadFile func(filename string) ([]byte, error)
+
+ // Render renders the given block of CommonMark as a present element.
+ Render func(p []byte) (Elem, error)
}
// ParseMode represents flags for the Parse function.
@@ -344,7 +347,10 @@ func (ctx *Context) Parse(r io.Reader, name string, mode ParseMode) (*Doc, error
// Parse parses a document from r. Parse reads assets used by the presentation
// from the file system using ioutil.ReadFile.
func Parse(r io.Reader, name string, mode ParseMode) (*Doc, error) {
- ctx := Context{ReadFile: ioutil.ReadFile}
+ ctx := Context{
+ ReadFile: ioutil.ReadFile,
+ Render: renderAsHTML,
+ }
return ctx.Parse(r, name, mode)
}
@@ -512,11 +518,12 @@ func parseSections(ctx *Context, name, prefix string, lines *Lines, number []int
block[i] = line
}
}
- html, err := renderMarkdown([]byte(strings.Join(block, "\n")))
+
+ elem, err := ctx.Render([]byte(strings.Join(block, "\n")))
if err != nil {
return nil, err
}
- e = HTML{HTML: html}
+ e = elem
default:
// Collect text lines.
@@ -698,16 +705,80 @@ func trimSpeakerNote(s string) string {
return strings.TrimPrefix(s, ": ")
}
-func renderMarkdown(input []byte) (template.HTML, error) {
+func renderAsHTML(input []byte) (Elem, error) {
md := goldmark.New(goldmark.WithRendererOptions(html.WithUnsafe()))
reader := text.NewReader(input)
doc := md.Parser().Parse(reader)
fixupMarkdown(doc)
var b strings.Builder
if err := md.Renderer().Render(&b, input, doc); err != nil {
- return "", err
+ return nil, err
}
- return template.HTML(b.String()), nil
+ return HTML{HTML: template.HTML(b.String())}, nil
+} |
This CL adds a new field to Context, to more easily access and customize the CommonMark rendering process from external packages. Fixes golang/go#48841. Change-Id: I0bb91480bb1acbf66c117dc266b52ccb62b35c6f
Change https://golang.org/cl/355049 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes.
also with
x/tools@v0.1.7
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
a
present.Doc
value withSections
filled withElem []present.Elem
fields of variouspresent.Xyz
types (present.Text
,present.List
, ...)What did you see instead?
when a
talk.slide
file is using the "new" Markdown syntax, allSections
have only oneElem
of typepresent.HTML
.each slide of the full talk has already been rendered to
html
using the underlying markdown package (yuin/goldmark
), by passing the expectedpresent.Xyz
structure.my sbinet/present-tex command was using the "data model" of
present
to render it toLaTeX+Beamer
.couldn't
present.parseSections
be modified to translate agoldmark
AST into the "old"present
data model instead of eagerly rendering everything tohtml
?The text was updated successfully, but these errors were encountered: