From ffffc8a506d4b8531876b0a093021f351bd93644 Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Sat, 17 Sep 2022 18:58:07 +0900 Subject: [PATCH] support code syntax --- app/syntax/quot.grammar | 5 +++-- app/syntax/quot.grammar.js | 14 +++++++------- app/syntax/quot.ts | 5 +++++ app/views/components/editor.css | 9 +++++++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/syntax/quot.grammar b/app/syntax/quot.grammar index 672e103..33ea2e9 100644 --- a/app/syntax/quot.grammar +++ b/app/syntax/quot.grammar @@ -1,7 +1,7 @@ @top Document { heading line* } heading { Heading? "\n" } -line { Indent* ((AutoLink | word) space*)* "\n" } +line { Indent* ((AutoLink | Code | word) space*)* "\n" } @tokens { space { $[ \t] } @@ -9,5 +9,6 @@ line { Indent* ((AutoLink | word) space*)* "\n" } Heading { ![\n]+ } Indent { space } AutoLink { ("http" | "https") "://" word } - @precedence { AutoLink, word } + Code { "`" ![`\n]+ "`" | ($[$%] " ") ![\n]+ } + @precedence { AutoLink, Code, word } } diff --git a/app/syntax/quot.grammar.js b/app/syntax/quot.grammar.js index 4f8db12..e78eddd 100644 --- a/app/syntax/quot.grammar.js +++ b/app/syntax/quot.grammar.js @@ -2,15 +2,15 @@ import {LRParser} from "@lezer/lr" export const parser = LRParser.deserialize({ version: 14, - states: "#rOQOPOOOOOO'#Cf'#CfOYOPO'#CfQ_OQOOOOOO,59Q,59QOOOO'#Cb'#CbOmOQO'#ChO{OSO'#CcOpOQO'#ChOOOO'#Ch'#ChOOOO'#Ca'#CaQ_OQOOOOOO-E6`-E6`O!ZOQO,59SOOOO,59S,59SOOOO'#Cd'#CdO!fOSO,58}OOOO-E6a-E6aOOOO-E6_-E6_OOOO1G.n1G.nOOOO-E6b-E6b", - stateData: "!w~OQQOZPO~OZSO~ORTOSVOZXO]VO~ORTOSVOZ^O]VO~O^_OSVXZVX]VX~OSVOZcO]VO~O^_OSVaZVa]Va~OS]~", - goto: "!T]PPPPP^dkvP|P!PQZRRbZSURZR[USWRZQ]UTaW]Q`VRd`RROTYRZ", - nodeNames: "⚠ Document Heading Indent AutoLink", - maxTerm: 14, + states: "#rOQOPOOOOOO'#Cg'#CgOYOPO'#CgQ_OQOOOOOO,59R,59ROOOO'#Cc'#CcOpOQO'#CiO!ROSO'#CdOsOQO'#CiOOOO'#Ci'#CiOOOO'#Cb'#CbQ_OQOOOOOO-E6a-E6aO!dOQO,59TOOOO,59T,59TOOOO'#Ce'#CeO!rOSO,59OOOOO-E6b-E6bOOOO-E6`-E6`OOOO1G.o1G.oOOOO-E6c-E6c", + stateData: "#Y~OQQO[PO~O[SO~ORTOSVOTVO[XO^VO~ORTOSVOTVO[^O^VO~O__OSWXTWX[WX^WX~OSVOTVO[cO^VO~O__OSWaTWa[Wa^Wa~OST^T~", + goto: "!U^PPPPPP_elwP}P!QQZRRbZSURZR[USWRZQ]UTaW]Q`VRd`RROTYRZ", + nodeNames: "⚠ Document Heading Indent AutoLink Code", + maxTerm: 15, skippedNodes: [0], repeatNodeCount: 4, - tokenData: "(U~RWOXkXY!^YZ!mZpkpq!^q#[k#[#]!r#]~kVrTQP]UOXkXY!RZpkpq!Rq~kP!WQQPOY!RZ~!RV!gQQPRQ^SOY!RZ~!R~!rOZ~V!yVQP]UOXkXY!RZpkpq!Rq#hk#h#i#`#i~kV#gVQP]UOXkXY!RZpkpq!Rq#hk#h#i#|#i~kV$TVQP]UOXkXY!RZpkpq!Rq#dk#d#e$j#e~kV$qXQP]UOXkXY!RZpkpq!Rq![k![!]%^!]#gk#g#h'h#h~kV%eVQP]UOXkXY!RZpkpq!Rq!Pk!P!Q%z!Q~kV&RVQP]UOXkXY!RZpkpq!Rq!Pk!P!Q&h!Q~kV&oTQP]UOX'OXY!RZp'Opq!Rq~'OV'XTQPSU]UOX'OXY!RZp'Opq!Rq~'OV'oVQP]UOXkXY!RZpkpq!Rq![k![!]%^!]~k", + tokenData: "+w~R]OXzXY!mYZ!|Zpzpq!mqtztu#Ruv#Rv#Sz#S#T$R#T#[z#[#]&e#]~zV!RTQP^UOXzXY!bZpzpq!bq~zP!gQQPOY!bZ~!bV!vQQPRQ_SOY!bZ~!b~#RO[~V#YTQP^UOXzXY!bZpzpq#iq~zV#nQQPOY#tZ~#tV#{QQPTUOY#tZ~#tV$YVQP^UOX$oXY%]Zp$opq%]q#S$o#S#Tz#T~$oV$vVQP^UOX$oXY%]Zp$opq%]q#S$o#S#T%{#T~$oV%bSQPOY%]Z#S%]#S#T%n#T~%]V%uQQPTUOY!bZ~!bV&UTQPTU^UOXzXY!bZpzpq!bq~zV&lVQP^UOXzXY!bZpzpq!bq#hz#h#i'R#i~zV'YVQP^UOXzXY!bZpzpq!bq#hz#h#i'o#i~zV'vVQP^UOXzXY!bZpzpq!bq#dz#d#e(]#e~zV(dXQP^UOXzXY!bZpzpq!bq![z![!])P!]#gz#g#h+Z#h~zV)WVQP^UOXzXY!bZpzpq!bq!Pz!P!Q)m!Q~zV)tVQP^UOXzXY!bZpzpq!bq!Pz!P!Q*Z!Q~zV*bTQP^UOX*qXY!bZp*qpq!bq~*qV*zTQPSU^UOX*qXY!bZp*qpq!bq~*qV+bVQP^UOXzXY!bZpzpq!bq![z![!])P!]~z", tokenizers: [0, 1, 2], topRules: {"Document":[0,1]}, - tokenPrec: 82 + tokenPrec: 97 }) diff --git a/app/syntax/quot.ts b/app/syntax/quot.ts index b3d4da4..ddba722 100644 --- a/app/syntax/quot.ts +++ b/app/syntax/quot.ts @@ -13,6 +13,7 @@ export const quotLanguage = LRLanguage.define({ Heading: t.heading, Indent: t.separator, AutoLink: t.link, + Code: t.monospace, }), ], }), @@ -38,5 +39,9 @@ export const quotHighlighting = syntaxHighlighting( tag: t.link, class: "auto-link", }, + { + tag: t.monospace, + class: "code", + }, ]) ); diff --git a/app/views/components/editor.css b/app/views/components/editor.css index 5f511cb..b3f9cfc 100644 --- a/app/views/components/editor.css +++ b/app/views/components/editor.css @@ -35,3 +35,12 @@ color: var(--nc-lk-2); cursor: pointer; } + +.editor .code { + background: var(--nc-bg-3); + border-radius: 0.25rem; + padding: 0.2rem 0.4rem; + font-size: 0.9rem; + font-family: var(--nc-font-mono); + font-weight: bold; +}