Skip to content

Commit

Permalink
Merge pull request #449 from rcarmo/gfm
Browse files Browse the repository at this point in the history
RFC: Markdown Rendering Support
  • Loading branch information
candid82 authored Mar 7, 2021
2 parents 224873a + 257bca7 commit 031dba9
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ <h2>Index of <a href="#joker-std-ns">Namespaces</a></h2>
<li>
<a href="#joker.math">joker.math</a>
</li>
<li>
<a href="#joker.markdown">joker.markdown</a>
</li>
<li>
<a href="#joker.os">joker.os</a>
</li>
Expand Down
61 changes: 61 additions & 0 deletions docs/joker.markdown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<html>

<head>
<link rel="stylesheet" type="text/css" href="main.css">
</head>

<body>
<div class="main">
<h1>Namespace: joker.base64</h1>
<span class="var-added">v1.0</span>
<h2>Contents</h2>
<ul>
<li>
<a href="#_summary">Summary</a>
</li>
<li>
<a href="#_index">Index</a>
</li>
<li>
<a href="#_constants">Constants</a>
</li>
<li>
<a href="#_variables">Variables</a>
</li>
<li>
<a href="#_functions">Functions, Macros, and Special Forms</a>
</li>
</ul>
<h2 id="_summary">Summary</h2>
<p class="var-docstr">Implements GitHub Flavored Markdown rendering.</p>
<h2 id="_index">Index</h2>
<ul class="index">
<li>
<a href="#convert-string">convert-string</a>
</li>
</ul>
<h2 id="_constants">Constants</h2>
Constants are variables with <tt>:const true</tt> in their metadata. Joker currently does not recognize them as
special; as such, it allows redefining them or their values.
<ul>
(None.)
</ul>
<h2 id="_variables">Variables</h2>
<ul>
(None.)
</ul>
<h2 id="_functions">Functions, Macros, and Special Forms</h2>
<ul>
<li>
<h3 class="Function" id="convert-string">convert-string</h3>
<span class="var-kind Function">Function</span>
<span class="var-added">v1.0</span>
<pre class="var-usage"><div><code>(convert-string s)</code></div></pre>
<p class="var-docstr">Returns the HTML rendering of Markdown string s.</p>
</li>
</ul>
</div>
</body>
<script src="main.js"></script>

</html>
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ require (
go.etcd.io/bbolt v1.3.3
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
gopkg.in/yaml.v2 v2.2.2
github.com/yuin/goldmark v1.3.2
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8Bz
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/pkg/profile v1.2.1 h1:F++O52m40owAmADcojzM+9gyjmMOY/T4oYJkgFDH8RE=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/yuin/goldmark v1.3.2 h1:YjHC5TgyMmHpicTgEqDN0Q96Xo8K6tLXPnmNOHXCgs0=
github.com/yuin/goldmark v1.3.2/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
_ "github.com/candid82/joker/std/http"
_ "github.com/candid82/joker/std/io"
_ "github.com/candid82/joker/std/json"
_ "github.com/candid82/joker/std/markdown"
_ "github.com/candid82/joker/std/math"
_ "github.com/candid82/joker/std/os"
_ "github.com/candid82/joker/std/strconv"
Expand Down
10 changes: 10 additions & 0 deletions std/markdown.joke
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns
^{:go-imports []
:doc "Implements GitHub Flavored Markdown rendering."}
markdown)

(defn ^String convert-string
"Returns the HTML rendering of Markdown string s"
{:added "1.0"
:go "convertString(s)"}
[^String s])
35 changes: 35 additions & 0 deletions std/markdown/a_markdown.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This file is generated by generate-std.joke script. Do not edit manually!

package markdown

import (
. "github.com/candid82/joker/core"
)

var __convert_string__P ProcFn = __convert_string_
var convert_string_ Proc = Proc{Fn: __convert_string__P, Name: "convert_string_", Package: "std/markdown"}

func __convert_string_(_args []Object) Object {
_c := len(_args)
switch {
case _c == 1:
s := ExtractString(_args, 0)
_res := convertString(s)
return MakeString(_res)

default:
PanicArity(_c)
}
return NIL
}

func Init() {

InternsOrThunks()
}

var markdownNamespace = GLOBAL_ENV.EnsureSymbolIsLib(MakeSymbol("joker.markdown"))

func init() {
markdownNamespace.Lazy = Init
}
22 changes: 22 additions & 0 deletions std/markdown/a_markdown_slow_init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This file is generated by generate-std.joke script. Do not edit manually!

package markdown

import (
"fmt"
. "github.com/candid82/joker/core"
"os"
)

func InternsOrThunks() {
if VerbosityLevel > 0 {
fmt.Fprintln(os.Stderr, "Lazily running slow version of markdown.InternsOrThunks().")
}
markdownNamespace.ResetMeta(MakeMeta(nil, `Implements GitHub Flavored Markdown rendering.`, "1.0"))

markdownNamespace.InternVar("convert-string", convert_string_,
MakeMeta(
NewListFrom(NewVectorFrom(MakeSymbol("s"))),
`Returns the HTML rendering of Markdown string s`, "1.0").Plus(MakeKeyword("tag"), String{S: "String"}))

}
35 changes: 35 additions & 0 deletions std/markdown/markdown_native.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package markdown

import (
"bytes"

"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer/html"
)

func convertString(source string) string {
md := goldmark.New(
goldmark.WithExtensions(
extension.GFM,
extension.Table,
extension.DefinitionList,
extension.Footnote,
extension.Typographer,
),
goldmark.WithParserOptions(
parser.WithAutoHeadingID(),
),
goldmark.WithRendererOptions(
html.WithHardWraps(),
html.WithXHTML(),
html.WithUnsafe(), // allow for raw markup
),
)
var buf bytes.Buffer
if err := md.Convert([]byte(source), &buf); err != nil {
panic(err)
}
return buf.String()
}

0 comments on commit 031dba9

Please sign in to comment.