Skip to content
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

Associate label to GitHub styled task lists. #42

Merged
merged 2 commits into from
Aug 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 37 additions & 21 deletions src/Common.fs
Expand Up @@ -25,28 +25,45 @@ module private Util =
let markedHighlight: obj -> Marked.MarkedExtension = importMember "marked-highlight"

let renderer =
let heading =
fun (text: string) (level: int) ->
let escapedText = Regex.Replace(string text, @"[^\w]+", "-")
let l = string level
let heading text level =
let escapedText = Regex.Replace(text, @"[^\w]+", "-")
let l = level

$"""<h{l}><a name="{escapedText}" class="anchor" href="#{escapedText}">{text}</a></h{l}>"""
$"""<h{l}><a name="{escapedText}" class="anchor" href="#{escapedText}">{text}</a></h{l}>"""

let link =
fun href title text ->
let ref =
match href with
| Some s -> mdToHtml s
| None -> ""
let link href title text =
let ref =
match href with
| Some s -> mdToHtml s
| None -> ""

let title =
match title with
| null -> text
| _ -> title
let title =
match title with
| null -> text
| _ -> title

$"""<a href="{ref}" title="{title}">{text}</a>"""
$"""<a href="{ref}" title="{title}">{text}</a>"""

let mops = !!{| heading = heading; link = link |}
let listitem text task check =
let checkState =
match check with
| true -> "checked"
| false -> ""

match task with
| true ->
$"""<li><label class="checkbox"><input type="checkbox" class="checkbox" disabled {checkState} />{text}</label></li>"""
| false -> $"""<li>{text}</li>"""

let checkbox _ =
// NOTE: checkbox generation is handled by listitem.
""

let mops =
!!{| heading = heading
link = link
listitem = listitem
checkbox = checkbox |}


jsOptions<Marked.MarkedExtension> (fun o ->
Expand All @@ -55,10 +72,9 @@ module private Util =
o.headerIds <- Some true)

let highlighter =
let highlight =
fun (code: string) (lang: string) ->
(hljs.highlight (code, !!{| language = lang |}))
.value
let highlight (code: string) (lang: string) =
(hljs.highlight (code, !!{| language = lang |}))
.value

markedHighlight !!{| highlight = highlight |}

Expand Down