aboutsummaryrefslogtreecommitdiff
path: root/_extensions
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-05-12 11:13:07 +0200
committerJonas Smedegaard <dr@jones.dk>2025-05-12 11:13:07 +0200
commit6d432681934a532f4429f57c0c92eb96ed3388c7 (patch)
tree6036268a74db5cfbda906f3db9ae681b0f81b67c /_extensions
parent621af34767486e942f0b6055018a6140bb61cf64 (diff)
cover CURIE type prefix; improve examples in comments
Diffstat (limited to '_extensions')
-rw-r--r--_extensions/ruc-play/semantic-markdown/semantic-markdown.lua116
1 files changed, 89 insertions, 27 deletions
diff --git a/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua b/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua
index 9213a1a..fb96abe 100644
--- a/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua
+++ b/_extensions/ruc-play/semantic-markdown/semantic-markdown.lua
@@ -5,39 +5,93 @@
---
--- ## Examples
---
---- Ideally, this text:
+--- The following Markdown text includes semantic annotations
+--- within braced enclosures:
---
---- ```Markdown+RDF
---- Simple ontological annotation:
---- [This]{foaf:depiction} is not a pipe.
+--- ```markdown
+--- # {=<#artwork> .:Image} Semantics
+---
+--- Simple ontological annotation:
+--- [This][painting] is not a [pipe].
+---
+--- Nested, mixed-use and custom-namespaced annotations:
+--- [[Ceci][painting] n'est pas une [pipe].]{lang=fr bibo:shortDescription}
+---
+--- [painting]: {wd:Q1061035}
+--- "A painting of a smoking pipe {:depiction}"
---
---- Nested, mixed-use and custom-namespaced annotations:
---- [[Ceci]{foaf:depiction} n'est pas une pipe.]{lang=fr bibo:Quote}
+--- [pipe]: {wd:Q104526}
+--- "A smoking pipe {:depicts}"
+---
+--- {@default}: foaf
---
--- {bibo}: http://purl.org/ontology/bibo/
+---
+--- {wd}: http://www.wikidata.org/entity/
--- ```
---
---- ...should with this filter be transformed to this text:
+--- This filter should transform the above text, with the command
+--- `pandoc -L semantic-markdown.lua -t commonmark --wrap=preserve`,
+--- into the below markdown text with semantic annotations as metadata:
---
---- ```Markdown
+--- ```markdown
--- ---
--- turtle: |
--- @prefix bibo: http://purl.org/ontology/bibo/
+--- @prefix foaf: http://xmlns.com/foaf/0.1/
+--- @prefix wd: https://www.wikidata.org/entity/
---
---- _:001 a foaf:depiction .
---- _:002 a foaf:depiction .
---- _:003 a bibo:Quote .
+--- <#artwork> a foaf:Image ;
+--- foaf:depiction <https://www.wikidata.org/entity/Q1061035> ;
+--- foaf:depicts <https://www.wikidata.org/entity/Q104526> ;
+--- bibo:shortDescription "Ceci n'est pas une pipe."@fr .
--- ---
---- Simple ontological annotation:
---- This is not a pipe.
+--- # Semantics
---
---- Nested, mixed-use and custom-namespaced annotations:
---- [Ceci n'est pas une pipe.]{lang=fr}
+--- Simple ontological annotation:
+--- [This][painting] is not a [pipe].
+---
+--- Nested, mixed-use and custom-namespaced annotations:
+--- [[Ceci][painting] n'est pas une [pipe].]{lang=fr}
+---
+--- [painting]: https://www.wikidata.org/entity/Q1061035
+--- "A painting of a smoking pipe"
+---
+--- [pipe]: https://www.wikidata.org/entity/Q104526
+--- "A smoking pipe"
--- ```
---
---- When target document format is html,
---- this filter should ideally produce RDFa 1.1 Lite or Core data.
---- (Lite is *not* a subset of Core as it deviates slightly).
+--- This filter should also transform the above text, with the command
+--- `pandoc -L semantic-markdown.lua -t html --wrap=preserve`,
+--- into the below HTML text with embedded RDFa Lite 1.1 anotations,
+--- modulo wrapping of long lines:
+---
+--- ```html
+--- <div vocab="http://xmlns.com/foaf/0.1/"
+--- prefix="bibo: http://purl.org/ontology/bibo/"
+--- resource="#artwork" typeof="Image">
+--- <h1>Semantics</h1>
+--- <p>Simple ontological annotation:<br />
+--- <a property="depiction"
+--- href="https://www.wikidata.org/entity/Q1061035"
+--- title="A painting of a smoking pipe">This</a>
+--- is not
+--- a <a property="depicts"
+--- href="https://www.wikidata.org/entity/Q104526"
+--- title="A smoking pipe">pipe</a>.</p>
+---
+--- <p>Nested, mixed-use and custom-namespaced annotations:<br />
+--- <span lang="fr" property="bibo:shortDescription">
+--- <a property="depiction"
+--- href="https://www.wikidata.org/entity/Q1061035"
+--- title="A painting of a smoking pipe">Ceci</a>
+--- n'est pas
+--- une <a property="depicts"
+--- href="https://www.wikidata.org/entity/Q104526"
+--- title="A smoking pipe">pipe</a>.
+--- </span></p>
+--- </div>
+--- ```
---
--- * v0.0.1
--- * initial release
@@ -74,6 +128,9 @@ local ElementTypeIsEnclosure = {
Strong = true,
}
+--- curie_type_prefix - `typeof` or `resource` attribute CURIE hint
+local curie_type_prefix = "[.=]?"
+
-- TODO: cover non-ASCII Unicode characters
-- @see <https://www.lua.org/manual/5.4/manual.html#6.5>
--- curie_prefix - CURIE prefix component as set of chars
@@ -118,6 +175,7 @@ local curie_default = ":"
--- # Annotated paragraph using a custom namespace
---
--- My favorite animal is the [Liger]{ov:preferredAnimal}.
+--- {=<#me> .:Person}
---
--- {ov}: http://open.vocab.org/terms/
--- ```
@@ -129,7 +187,7 @@ local curie_default = ":"
local function Namespaces(blocks)
-- paragraph with only a braced prefix-only CURIE, colon and one word
- local curie_pattern = "^{"..curie_prefix.."}:$"
+ local curie_pattern = "^{"..curie_type_prefix..curie_prefix.."}:$"
if #blocks.content == 3
and blocks.content[1].t == "Str"
and blocks.content[2].t == "Space"
@@ -182,10 +240,10 @@ end
--- a bc CURIEa d
---
--- Nested and mixed-use annotations:
---- ["[Ceci]{foaf:depiction} n'est pas une pipe"]{lang=fr dc:Text}
---- | | ||\~~~~~~~~~~~~/| || \~~~~~/|
---- a a1 |c1 CURIEa d1 bc CURIEb d
---- b1
+--- ["Ceci n'est pas une [pipe]{foaf:depicts lang=fr}"]{dc:description}
+--- | | ||\~~~~~~~~~~/ | ||\~~~~~~~~~~~~/|
+--- a a1 |c1 CURIEa d1bc CURIEb d
+--- b1
---
--- Chained hypermedia and ontological annotations:
--- "A [map](https://osm.org/){foaf:depiction} is not the territory"
@@ -339,10 +397,14 @@ local function Statements (block)
-- in braced enclosure, leaving it
-- TODO: support mixed-use enclosure
if encl == Enclosure.BRACED then
- local _, nextpos1 = el.text:find("^"..curie_long.."}", pos)
- local _, nextpos2 = el.text:find("^"..curie_no_ref.."}", pos)
- local _, nextpos3 = el.text:find("^"..curie_local.."}", pos)
- local _, nextpos4 = el.text:find("^"..curie_default.."}", pos)
+ local curie_pattern1 = "^"..curie_type_prefix..curie_long.."}"
+ local curie_pattern2 = "^"..curie_type_prefix..curie_no_ref.."}"
+ local curie_pattern3 = "^"..curie_type_prefix..curie_local.."}"
+ local curie_pattern4 = "^"..curie_type_prefix..curie_default.."}"
+ local _, nextpos1 = el.text:find(curie_pattern1, pos)
+ local _, nextpos2 = el.text:find(curie_pattern2, pos)
+ local _, nextpos3 = el.text:find(curie_pattern3, pos)
+ local _, nextpos4 = el.text:find(curie_pattern4, pos)
local nextpos = nextpos1 or nextpos2 or nextpos3 or nextpos4
if nextpos then
statement_count = statement_count + 1