Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Fix markdig codeblock extension for < and > 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Jul 13, 2022
1 parent 8b01eb5 commit ccf803d
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 183 deletions.
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 0.5.4+8b01eb5 (Released 2022-7-13)
* Additions:
* latest commit #8b01eb5
* [[#8b01eb5](https://github.com/Freymaurer/Nfdi4Plants.Fornax/commit/8b01eb56b01e47ddf5a07d7cdef97368bc266914)] Update terser rollup config

### 0.5.3+da2f374 (Released 2022-7-11)
* Additions:
* latest commit #da2f374
Expand Down
32 changes: 32 additions & 0 deletions client/docs/CodeExamples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
layout: docs
title: Code Examples
published: 2022-05-09
Author: Dominik Brilhaus <https://orcid.org/0000-0001-9021-3197>
add toc: true
add sidebar: sidebars\mainSidebar.md
Article Status: draft
To-Dos:
- write
---


```
// Code testing no language
let x = 2010
```

```fsharp
// Code testing with language
let x = 20
```

Code testing with inline `code` example!

```bash
// Code testing with multiple < >

# https://git.nfdi4plants.org/<yourusername>/<yourarc>
```
137 changes: 0 additions & 137 deletions client/docs/PIDs.md

This file was deleted.

14 changes: 0 additions & 14 deletions client/docs/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ for f in *.md; do pandoc -s -o "${f%.md}.docx" "$f"; done

## What is metadata?

```
// Code testing no language
let x = 2010
```

```fsharp
// Code testing with language
let x = 20
```

Code testing with inline `code` example!

Metadata is "data that provides information about other data"[^1][Merriam]. In order to put some (plant) life into this web dictionary explanation, let us explore metadata with a plant biology example:

> Viola investigates the effect of the plant circadian clock on sugar metabolism in *W. mirabilis*. For her PhD project, which is part of an EU-funded consortium in Prof. Beetroot's lab, she acquires seeds from a South-African botanical society. Viola grows the plants under different light regimes, harvests leaves from a two-day time series experiment, extracts polar metabolites as well as RNA and submits the samples to nearby core facilities for metabolomics and transcriptomics measurements, respectively. After a few weeks of iterative consultation with the facilities' heads as well as technicians and computational biologists involved, Viola receives back a wealth of raw and processed data. From the data she produces figures and wraps everything up to publish the results in the *Journal of Wonderful Plant Sciences*.
Expand Down
7 changes: 2 additions & 5 deletions client/docs/sidebars/mainSidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ To-Dos:
## DataPLANT Support:/docs/metadata.html#dataplant-support
```

```Data Management Plan
# Data Management Plan:/docs/DataManagementPlan.html
## Advantages of a DMP:/docs/DataManagementPlan.html#advantages-of-a-dmp
## Elements of a DMP:/docs/DataManagementPlan.html#elements-of-a-dmp
## DataPLANT's Data Management Plan Generator:/docs/DataManagementPlan.html#dataplants-data-management-plan-generator
```Fornax Testing Example
# Code Examples:/docs/CodeExamples.html
```
4 changes: 2 additions & 2 deletions client/loaders/docsloader.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ let loader (projectRoot: string) (siteContent: SiteContents) =
printfn "LOADER CURRENT DOCS: %i" <| Seq.length doc
printfn "LOADER ADDING DOCS: %i" <| Seq.length docs

/// Alternative.
let sc = new SiteContents()
// Alternative
// let sc = new SiteContents()

docs
|> Array.iter siteContent.Add
Expand Down
45 changes: 22 additions & 23 deletions src/Nfdi4Plants.Fornax/MarkdigExtensions/nfdi-code.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,37 @@ module NfdiCode =
type NFDICodeBlockRenderer() =
inherit HtmlObjectRenderer<CodeBlock>()

let extractSourcecode (node: LeafBlock) =
let code = new StringBuilder()
let lines = node.Lines.Lines
let totalLines = lines.Length
let rec appendLines (counter: int) (c: StringBuilder) =
if counter >= totalLines then
c
else
let line = lines[counter]
let slice = line.Slice
if isNull slice.Text then
appendLines (counter + 1) c
else
let lineText = slice.Text.Substring(slice.Start, slice.Length);
if counter > 0 then
appendLines (counter+1) (c.AppendLine().Append(lineText))
else
appendLines (counter+1) (c.Append(lineText))
appendLines 0 code
|> fun x -> x.ToString()
//let extractSourcecode (node: LeafBlock) =
// let code = new StringBuilder()
// let lines = node.Lines.Lines
// let totalLines = lines.Length
// let rec appendLines (counter: int) (c: StringBuilder) =
// if counter >= totalLines then
// c
// else
// let line = lines[counter]
// let slice = line.Slice
// if isNull slice.Text then
// appendLines (counter + 1) c
// else
// let lineText = slice.Text.Substring(slice.Start, slice.Length);
// if counter > 0 then
// appendLines (counter+1) (c.AppendLine().Append(lineText))
// else
// appendLines (counter+1) (c.Append(lineText))
// appendLines 0 code
// |> fun x -> x.ToString()

override this.Write(renderer : HtmlRenderer , cb : CodeBlock ) =

if cb :? FencedCodeBlock && cb.Parser :? FencedCodeBlockParser then
let fcb = cb :?> FencedCodeBlock
let parser = cb.Parser :?> FencedCodeBlockParser
let languageCode = fcb.Info.Replace(parser.InfoPrefix, "").Trim()
let code = extractSourcecode(cb)
if languageCode = "" then
renderer
.Write("<nfdi-code>")
.Write(code)
.WriteLeafRawLines(cb, true, true, true)
.Write("</nfdi-code>")
|> ignore
else
Expand All @@ -57,7 +56,7 @@ module NfdiCode =
.Write("<nfdi-code")
.WriteAttributes(attributes)
.Write(">")
.Write(code)
.WriteLeafRawLines(cb, true, true, true)
.Write("</nfdi-code>")
|> ignore
renderer.EnsureLine() |> ignore
Expand Down
12 changes: 10 additions & 2 deletions tests/Nfdi4Plants.Fornax.Tests/nfdi-code.tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let someCode = 42
```
"""
let result = Markdown.ToHtml(markdown, pipeline)
let expected = $"""<p>Test line</p>{'\010'}<nfdi-code>let someCode = 42</nfdi-code>{'\010'}"""
let expected = $"""<p>Test line</p>{'\010'}<nfdi-code>let someCode = 42{'\010'}</nfdi-code>{'\010'}"""
Expect.equal result expected ""
}
test "Fenced code block" {
Expand All @@ -38,7 +38,15 @@ let someCode = 42
```
"""
let result = Markdown.ToHtml(markdown, pipeline)
let expected = $"""<p>Test line</p>{'\010'}<nfdi-code class="language-fsharp">let someCode = 42</nfdi-code>{'\010'}"""
let expected = $"""<p>Test line</p>{'\010'}<nfdi-code class="language-fsharp">let someCode = 42{'\010'}</nfdi-code>{'\010'}"""
Expect.equal result expected ""
}
test "html like structure case" {
let markdown = """```
# https://git.nfdi4plants.org/<yourusername>/<yourarc>
```"""
let result = Markdown.ToHtml(markdown, pipeline)
let expected = $"""<nfdi-code># https://git.nfdi4plants.org/&lt;yourusername>/&lt;yourarc>{'\010'}</nfdi-code>{'\010'}"""
Expect.equal result expected ""
}
]

0 comments on commit ccf803d

Please sign in to comment.