Skip to content

Commit

Permalink
See #49
Browse files Browse the repository at this point in the history
For now, I've disabled the `MathAJax` extension, though I created a stub in nodeProcessing.go for future consideration.
Also, replaced the `panic()` call with `fmt.Printf()` when node.(type)
does not match any of the supported types. This way, people could report such
issues and at least get some useful output, rather than a crash.
  • Loading branch information
jessp01 committed Nov 2, 2023
1 parent 34af9a0 commit 4bdd5ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions mdtopdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"fmt"
"io"
"os"
"reflect"

"strings"

"github.com/go-pdf/fpdf"
Expand Down Expand Up @@ -338,7 +338,8 @@ func (r *PdfRenderer) Run(content []byte) error {
s = []byte(r.unicodeTranslator(string(s)))
}

exts := parser.CommonExtensions // parser.OrderedListStart | parser.NoEmptyLineBeforeBlock
// exts := parser.CommonExtensions // parser.OrderedListStart | parser.NoEmptyLineBeforeBlock
exts := parser.NoIntraEmphasis | parser.Tables | parser.FencedCode | parser.Autolink | parser.Strikethrough | parser.SpaceHeadings | parser.HeadingIDs | parser.BackslashLineBreak | parser.DefinitionLists
p := parser.NewWithExtensions(exts)
doc := markdown.Parse(s, p)
_ = markdown.Render(doc, r)
Expand Down Expand Up @@ -450,8 +451,10 @@ func (r *PdfRenderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.
r.processTableRow(node, entering)
case *ast.TableCell:
r.processTableCell(*node, entering)
/*case *ast.Math:
r.processMath(node)*/
default:
panic("Unknown node type " + reflect.TypeOf(node).Name())
fmt.Printf("Unknown node type: %T. Skipping\n", node)
}
return ast.GoToNext
}
Expand Down
7 changes: 7 additions & 0 deletions nodeProcessing.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ func (r *PdfRenderer) processText(node *ast.Text) {
}
}

// This is a stub implementation. For now, the MathAjax extension is disabled.
func (r *PdfRenderer) processMath(node *ast.Math) {
currentStyle := r.cs.peek().textStyle
s := string(node.Literal)
r.write(currentStyle, s)
}

func (r *PdfRenderer) outputUnhighlightedCodeBlock(codeBlock string) {
r.cr() // start on next line!
r.setStyler(r.Backtick)
Expand Down

0 comments on commit 4bdd5ab

Please sign in to comment.