From e7558285fda58e68d21905581474c686081eeda8 Mon Sep 17 00:00:00 2001 From: Bernhard Berger Date: Fri, 26 Apr 2024 15:42:14 +0200 Subject: [PATCH] Add djot --- website/package.json | 1 + website/src/parsers/djot/codeExample.txt | 13 ++++++++ website/src/parsers/djot/djot.js | 40 ++++++++++++++++++++++++ website/src/parsers/djot/index.js | 6 ++++ website/yarn.lock | 5 +++ 5 files changed, 65 insertions(+) create mode 100644 website/src/parsers/djot/codeExample.txt create mode 100644 website/src/parsers/djot/djot.js create mode 100644 website/src/parsers/djot/index.js diff --git a/website/package.json b/website/package.json index 6043538e..bb4e62f5 100644 --- a/website/package.json +++ b/website/package.json @@ -48,6 +48,7 @@ "@babel/eslint-parser": "~7.13.0", "@babel/runtime": "^7.16.3", "@creditkarma/thrift-parser": "^1.2.0", + "@djot/djot": "^0.3.1", "@gengjiawen/monkey-wasm": "^0.7.0", "@glimmer/compiler": "^0.83.1", "@glimmer/syntax": "^0.83.1", diff --git a/website/src/parsers/djot/codeExample.txt b/website/src/parsers/djot/codeExample.txt new file mode 100644 index 00000000..a5d851de --- /dev/null +++ b/website/src/parsers/djot/codeExample.txt @@ -0,0 +1,13 @@ +# Hello + +Some *emphasis*, **importance**, and `code`. + +--- + +```javascript +console.log('!'); +``` + +* foo +* bar +* baz diff --git a/website/src/parsers/djot/djot.js b/website/src/parsers/djot/djot.js new file mode 100644 index 00000000..2f83d384 --- /dev/null +++ b/website/src/parsers/djot/djot.js @@ -0,0 +1,40 @@ +import React from 'react'; +import defaultParserInterface from '../utils/defaultParserInterface'; + +const ID = 'djot'; + +export default { + ...defaultParserInterface, + + id: ID, + displayName: ID, + version: '0.3.1', + homepage: 'https://djot.net/', + locationProps: new Set(['pos']), + + loadParser(callback) { + require(['@djot/djot'], callback); + }, + + parse(djot, code, options) { + return djot.parse(code, { sourcePositions: true }); + }, + + getNodeName(node) { + return node.type; + }, + + nodeToRange({ pos }) { + if (pos) { + return [pos.start.offset, pos.end.offset]; + } + }, + + opensByDefault(node, key) { + return key === 'children'; + }, + + getDefaultOptions() { + return {}; + }, +}; diff --git a/website/src/parsers/djot/index.js b/website/src/parsers/djot/index.js new file mode 100644 index 00000000..f2b5994b --- /dev/null +++ b/website/src/parsers/djot/index.js @@ -0,0 +1,6 @@ +import 'codemirror/mode/markdown/markdown'; + +export const id = 'djot'; +export const displayName = 'Djot'; +export const mimeTypes = ['text/djot']; +export const fileExtension = 'dj'; diff --git a/website/yarn.lock b/website/yarn.lock index fe8e9dd8..3fd684fc 100644 --- a/website/yarn.lock +++ b/website/yarn.lock @@ -1196,6 +1196,11 @@ resolved "https://registry.yarnpkg.com/@creditkarma/thrift-parser/-/thrift-parser-1.2.0.tgz#69b47dff3d2a5211e9417ff543ea65f681821906" integrity sha512-mSRxjSXvU6sBfWhMBWXl7H/XEKWHQ7x+MUDLwyeFIwwX9UaZKPOc7TgGd0N78kcZtIMk82ArdxO6aFhqnBuNtg== +"@djot/djot@^0.3.1": + version "0.3.1" + resolved "https://registry.yarnpkg.com/@djot/djot/-/djot-0.3.1.tgz#9809897bb9b882d87d7d27976dd5fdb35e02af0b" + integrity sha512-jFYDPI8xLo7lz4V28ZaGRW+0E6lhRPijxNEb6Dj00Vo8twCd4Yb0A7Fug8clYTe1Le2ghl/uUcKGGTsN/avmHA== + "@eslint/eslintrc@^1.1.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.1.0.tgz#583d12dbec5d4f22f333f9669f7d0b7c7815b4d3"