diff --git a/scripts/md2html/md2html.js b/scripts/md2html/md2html.js index 6abbc024a9..a49fe7e98b 100644 --- a/scripts/md2html/md2html.js +++ b/scripts/md2html/md2html.js @@ -48,22 +48,99 @@ hljs.registerLanguage('uri', function() { ], } }); -hljs.registerLanguage('eventstream', function() { +hljs.registerLanguage('multipart', function() { return { + // This is a very limited approach that only + // detects boundaries and headers that start + // with "Content-" contains: [ { - scope: "attr", - begin: /^/, - end: ":", + scope: "meta", + match: /^--.*$/, }, { scope: "literal", - begin: /: */, + begin: /^Content-/, + end: /$/, + contains: [ + { + scope: "attr", + begin: " ", + end: /$/, + }, + ] + }, + ], + } + }); +hljs.registerLanguage('eventstream', function() { + return { + contains: [ + { + scope: "comment", + begin: /^:/, end: /$/, }, + { + scope: "attr", + match: /^[^:]+/ + }, ], } }); +hljs.registerLanguage('jsonseq', function() { + return { + keywords: ["true", "false", "null"], + contains: [ + { + scope: "meta", + match: /0[xX]1[eE]/, + }, + { + scope: "attr", + begin: /"(\\.|[^\\"\r\n])*"(?=\s*:)/, + relevance: 1.01 + }, + { + scope: "punctuation", + match: /[{}[\],:]/, + relevance: 0 + }, + { + scope: "literals", + beginKeywords: ["true", "false" , "null"].join(" "), + }, + hljs.QUOTE_STRING_MODE, + hljs.C_NUMBER_MODE + ] + } + }); +hljs.registerLanguage('jsonl', function() { + return { + aliases: ["ndjson"], + keywords: ["true", "false", "null"], + contains: [ + { + scope: 'attr', + begin: /"(\\.|[^\\"\r\n])*"(?=\s*:)/, + relevance: 1.01 + }, + { + scope: "punctuation", + match: /[{}[\],:]/, + relevance: 0 + }, + { + scope: "literals", + beginKeywords: ["true", "false" , "null"].join(" "), + }, + hljs.QUOTE_STRING_MODE, + hljs.C_NUMBER_MODE + ] + } + }); + + const cheerio = require('cheerio'); let argv = require('yargs') diff --git a/tests/md2html/fixtures/basic-new.html b/tests/md2html/fixtures/basic-new.html index b1ac32d1c6..7f04b29f3d 100644 --- a/tests/md2html/fixtures/basic-new.html +++ b/tests/md2html/fixtures/basic-new.html @@ -45,14 +45,62 @@
https://foo.com/bar{?baz*,qux}
-data: This data is formatted
-data: across two lines
-retry: 5
+--boundary-example
+Content-Type: application/openapi+yaml
+Content-Location: https://inaccessible-domain.com/api/openapi.yaml
+
+openapi: 3.2.0
+info:
+ title: Example API
+ version: 1.0
+ externalDocs:
+ url: docs.html
+
+--boundary-example
+Content-Type: text/html
+Content-Location: https://example.com/api/docs.html
+
+<html>
+ <head>
+ <title>API Documentation</title>
+ </head>
+ <body>
+ <p>Awesome documentation goes here</p>
+ </body>
+</html>
+
+event: addString
+data: This data is formatted
+data: across two lines
+retry: 5
+
+event: addNumber
+data: 1234.5678
+unknownField: this is ignored
-event: add
-data: 1234.5678
-unknown-field: this is ignored
-
+: This is a comment
+event: addJSON
+data: {"foo": 42}
+
+{"event": "addString", "data": "This data is formatted\nacross two lines", "retry": 5}
+{"event": "addNumber", "data": "1234.5678"}
+{"event": "addJSON", "data": "{\"foo\": 42}"}
+
+{"event": "addString", "data": "This data is formatted\nacross two lines", "retry": 5}
+{"event": "addNumber", "data": "1234.5678"}
+{"event": "addJSON", "data": "{\"foo\": 42}"}
+
+0x1E{
+ "timestamp": "1985-04-12T23:20:50.52Z",
+ "level": 1,
+ "message": "Hi!"
+}
+0x1E{
+ "timestamp": "1985-04-12T23:20:51.37Z",
+ "level": 1,
+ "message": "Bye!"
+}
+