From d1a8974758f49bbe602f5491e3f6e6513e615b8b Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Thu, 13 May 2021 13:49:14 +1000 Subject: [PATCH 1/4] interface: bump indigo --- pkg/interface/package-lock.json | 8 +++++--- pkg/interface/package.json | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/interface/package-lock.json b/pkg/interface/package-lock.json index e2ab86de08..71309dcafa 100644 --- a/pkg/interface/package-lock.json +++ b/pkg/interface/package-lock.json @@ -1483,9 +1483,9 @@ "integrity": "sha512-xO8hj2Ak6cEYe2QCM3w7UuaSB8ubg6G0G6/OkPVMVrz6b5ztccZmkbmYCYJ/Ot6976lGzKFsWFKRUhwRgCHfHQ==" }, "@tlon/indigo-react": { - "version": "1.2.22", - "resolved": "https://registry.npmjs.org/@tlon/indigo-react/-/indigo-react-1.2.22.tgz", - "integrity": "sha512-8w2TkYicch+R0kkZT+MZ4oG0pIJFNjhmVlbXgqyXhOCPRJB2WrAh6OM5Cbb389r7lA+CXXfu3Nx7Rdiuxjf/vg==", + "version": "1.2.23", + "resolved": "https://registry.npmjs.org/@tlon/indigo-react/-/indigo-react-1.2.23.tgz", + "integrity": "sha512-RH9106bWwRjLm91vnVRmdtPeXNg0YujsaBNwPt7Wsezj1IKVJKabGu50dRY7bovfBbiE5JhBZzA3lw3LABfj/w==", "requires": { "@reach/menu-button": "^0.10.5", "react": "^16.13.1", @@ -11313,6 +11313,7 @@ "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", "dev": true, + "optional": true, "requires": { "is-extendable": "^0.1.0" } @@ -11379,6 +11380,7 @@ "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", "integrity": "sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU=", "dev": true, + "optional": true, "requires": { "kind-of": "^3.0.2" } diff --git a/pkg/interface/package.json b/pkg/interface/package.json index 3faf280f74..17607d42b8 100644 --- a/pkg/interface/package.json +++ b/pkg/interface/package.json @@ -11,7 +11,7 @@ "@react-spring/web": "^9.1.1", "@tlon/indigo-dark": "^1.0.6", "@tlon/indigo-light": "^1.0.7", - "@tlon/indigo-react": "^1.2.22", + "@tlon/indigo-react": "^1.2.23", "@tlon/sigil-js": "^1.4.3", "@urbit/api": "file:../npm/api", "any-ascii": "^0.1.7", From 06cce27924e584c9f9fcf7123ed8dda7440ede7a Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Mon, 17 May 2021 10:15:04 +1000 Subject: [PATCH 2/4] GraphContent: fix blockquotes and newlines --- .../components/Graph/GraphContent.tsx | 11 +- .../landscape/components/Graph/blockquote.js | 124 ++++++++++++++++++ .../views/landscape/components/Graph/parse.ts | 20 ++- .../components/Graph/remark-break.ts | 24 ++++ .../landscape/components/Graph/resume.js | 10 ++ 5 files changed, 179 insertions(+), 10 deletions(-) create mode 100644 pkg/interface/src/views/landscape/components/Graph/blockquote.js create mode 100644 pkg/interface/src/views/landscape/components/Graph/remark-break.ts create mode 100644 pkg/interface/src/views/landscape/components/Graph/resume.js diff --git a/pkg/interface/src/views/landscape/components/Graph/GraphContent.tsx b/pkg/interface/src/views/landscape/components/Graph/GraphContent.tsx index b16677bea4..c70235a8d1 100644 --- a/pkg/interface/src/views/landscape/components/Graph/GraphContent.tsx +++ b/pkg/interface/src/views/landscape/components/Graph/GraphContent.tsx @@ -234,7 +234,7 @@ const header = ({ children, depth, ...rest }) => { const renderers = { heading: header, break: () => { - return ; + return
}, thematicBreak: () => { return ; @@ -274,12 +274,11 @@ const renderers = { return ( {children} @@ -287,9 +286,9 @@ const renderers = { }, paragraph: ({ children }) => { return ( - + {children} - + ); }, listItem: ({ children }) => { diff --git a/pkg/interface/src/views/landscape/components/Graph/blockquote.js b/pkg/interface/src/views/landscape/components/Graph/blockquote.js new file mode 100644 index 0000000000..a6cba106d6 --- /dev/null +++ b/pkg/interface/src/views/landscape/components/Graph/blockquote.js @@ -0,0 +1,124 @@ +/** pulled from remark-parse + * + * critical change is that blockquotes require a newline to be continued, see + * the `if(!prefixed) conditional + */ +'use strict' + +var trim = require('trim') +var interrupt = require('remark-parse/lib/util/interrupt') + +module.exports = blockquote + +var lineFeed = '\n' +var tab = '\t' +var space = ' ' +var greaterThan = '>' + +function blockquote(eat, value, silent) { + var self = this + var offsets = self.offset + var tokenizers = self.blockTokenizers + var interruptors = self.interruptBlockquote + var now = eat.now() + var currentLine = now.line + var length = value.length + var values = [] + var contents = [] + var indents = [] + var add + var index = 0 + var character + var rest + var nextIndex + var content + var line + var startIndex + var prefixed + var exit + + while (index < length) { + character = value.charAt(index) + + if (character !== space && character !== tab) { + break + } + + index++ + } + + if (value.charAt(index) !== greaterThan) { + return + } + + if (silent) { + return true + } + + index = 0 + + while (index < length) { + nextIndex = value.indexOf(lineFeed, index) + startIndex = index + prefixed = false + + if (nextIndex === -1) { + nextIndex = length + } + + while (index < length) { + character = value.charAt(index) + + if (character !== space && character !== tab) { + break + } + + index++ + } + + if (value.charAt(index) === greaterThan) { + index++ + prefixed = true + + if (value.charAt(index) === space) { + index++ + } + } else { + index = startIndex + } + + content = value.slice(index, nextIndex) + + if (!prefixed && !trim(content)) { + index = startIndex + break + } + + if (!prefixed) { + break; + } + + line = startIndex === index ? content : value.slice(startIndex, nextIndex) + + indents.push(index - startIndex) + values.push(line) + contents.push(content) + + index = nextIndex + 1 + } + + index = -1 + length = indents.length + add = eat(values.join(lineFeed)) + + while (++index < length) { + offsets[currentLine] = (offsets[currentLine] || 0) + indents[index] + currentLine++ + } + + exit = self.enterBlock() + contents = self.tokenizeBlock(contents.join(lineFeed), now) + exit() + + return add({type: 'blockquote', children: contents}) +} diff --git a/pkg/interface/src/views/landscape/components/Graph/parse.ts b/pkg/interface/src/views/landscape/components/Graph/parse.ts index 5b01e8badf..d5ef61741f 100644 --- a/pkg/interface/src/views/landscape/components/Graph/parse.ts +++ b/pkg/interface/src/views/landscape/components/Graph/parse.ts @@ -1,6 +1,14 @@ import remark from 'remark'; import RemarkDisableTokenizers from 'remark-disable-tokenizers'; import RemarkBreaks from 'remark-breaks'; +import ResumeParse from './resume'; +import newlines from './remark-break'; + +export interface ParserSettings { + inList: boolean; + inBlock: boolean; + inLink: boolean; +} const DISABLED_BLOCK_TOKENS = [ 'indentedCode', @@ -15,9 +23,14 @@ const DISABLED_BLOCK_TOKENS = [ const DISABLED_INLINE_TOKENS = ['autoLink', 'url', 'email', 'reference', 'html']; -const tallParser = remark().freeze(); +const tallParser = remark(); -export const parseTall = (text: string) => tallParser.parse(text); +export const parseTall = (text: string, settings: ParserSettings) => { + const res = tallParser.parse(text); + //const { inList, inBlock, inLink } = parser.Parser; + + return res; +} const wideParser = remark() .use([ @@ -28,8 +41,7 @@ const wideParser = remark() inline: DISABLED_INLINE_TOKENS, }, ], - RemarkBreaks, + newlines ]) - .freeze(); export const parseWide = (text: string) => wideParser.parse(text); diff --git a/pkg/interface/src/views/landscape/components/Graph/remark-break.ts b/pkg/interface/src/views/landscape/components/Graph/remark-break.ts new file mode 100644 index 0000000000..7b87cea2dd --- /dev/null +++ b/pkg/interface/src/views/landscape/components/Graph/remark-break.ts @@ -0,0 +1,24 @@ +import blockquote from './blockquote'; + +function lineBreak(eat, value: string, silent) { + let index = -1; + let character: string | null; + while(++index < length ) { + character = value.charAt(index) + if(character === '\n') { + eat(character)({type : 'break' }) + } else { + return; + } + } +} + +lineBreak.locator = function(value, fromIndex) { + return value.indexOf('\n', fromIndex); +} + +export default function plugin() { + this.Parser.prototype.blockTokenizers.break = lineBreak; + this.Parser.prototype.inlineTokenizers.break = lineBreak; + this.Parser.prototype.blockTokenizers.blockquote = blockquote; +} diff --git a/pkg/interface/src/views/landscape/components/Graph/resume.js b/pkg/interface/src/views/landscape/components/Graph/resume.js new file mode 100644 index 0000000000..76781d5f12 --- /dev/null +++ b/pkg/interface/src/views/landscape/components/Graph/resume.js @@ -0,0 +1,10 @@ + +export default function ResumeParse(settings) { + let parser = {}; + function create() { + parser.current = this.Parser; + Object.assign(this.Parser, settings); + } + + return [parser, create] +} From 201a4ad0a5461814435bd0848c3defac09bdb3ca Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Mon, 17 May 2021 10:23:27 +1000 Subject: [PATCH 3/4] GraphContent: use indigo list components --- .../components/Graph/GraphContent.tsx | 32 ++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/pkg/interface/src/views/landscape/components/Graph/GraphContent.tsx b/pkg/interface/src/views/landscape/components/Graph/GraphContent.tsx index c70235a8d1..d9a8cc3edb 100644 --- a/pkg/interface/src/views/landscape/components/Graph/GraphContent.tsx +++ b/pkg/interface/src/views/landscape/components/Graph/GraphContent.tsx @@ -3,7 +3,8 @@ import { Col, H1, H2, H3, - H4, Text + H4, Text, + Li, Ol, Ul } from '@tlon/indigo-react'; import { Content, ReferenceContent } from '@urbit/api'; import _ from 'lodash'; @@ -254,16 +255,12 @@ const renderers = { }, strong: ({ children }) => { return ( - - {children} - + {children} ); }, emphasis: ({ children }) => { return ( - - {children} - + {children} ); }, blockquote: ({ children, depth, tall, ...rest }) => { @@ -293,22 +290,11 @@ const renderers = { }, listItem: ({ children }) => { return ( - - - {children} - +
  • {children}
  • ); }, code: ({ language, tall, value, ...rest }) => { - console.log(rest); const inner = ( ); }, - list: ({ depth, children }) => { - return ( - - {children} - - ); + list: ({ depth, ordered, children }) => { + return ordered ?
      {children}
    :
      {children}
    ; }, 'graph-mention': ({ ship }) => , image: ({ url }) => ( From b60e39545c37a99738b3cf5fcb8025efdcd95742 Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Tue, 18 May 2021 12:10:58 +1000 Subject: [PATCH 4/4] GraphContent: fix tsc --- .../src/views/landscape/components/Graph/parse.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pkg/interface/src/views/landscape/components/Graph/parse.ts b/pkg/interface/src/views/landscape/components/Graph/parse.ts index d5ef61741f..1bace37872 100644 --- a/pkg/interface/src/views/landscape/components/Graph/parse.ts +++ b/pkg/interface/src/views/landscape/components/Graph/parse.ts @@ -23,14 +23,9 @@ const DISABLED_BLOCK_TOKENS = [ const DISABLED_INLINE_TOKENS = ['autoLink', 'url', 'email', 'reference', 'html']; -const tallParser = remark(); +const tallParser = remark().freeze(); -export const parseTall = (text: string, settings: ParserSettings) => { - const res = tallParser.parse(text); - //const { inList, inBlock, inLink } = parser.Parser; - - return res; -} +export const parseTall = (text: string) => tallParser.parse(text); const wideParser = remark() .use([