-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
progfay
committed
Jun 13, 2021
1 parent
e22a59a
commit 0d455d2
Showing
56 changed files
with
1,087 additions
and
1,004 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--- | ||
name: Custom issue template | ||
about: Describe this issue template's purpose here. | ||
title: '' | ||
labels: '' | ||
assignees: '' | ||
title: "" | ||
labels: "" | ||
assignees: "" | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
import type { Row } from './Row' | ||
import type { Row } from "./Row"; | ||
|
||
export interface CodeBlockPack { | ||
type: 'codeBlock' | ||
rows: Row[] | ||
type: "codeBlock"; | ||
rows: Row[]; | ||
} | ||
|
||
export interface CodeBlock { | ||
indent: number | ||
type: 'codeBlock' | ||
fileName: string | ||
content: string | ||
indent: number; | ||
type: "codeBlock"; | ||
fileName: string; | ||
content: string; | ||
} | ||
|
||
export const convertToCodeBlock = (pack: CodeBlockPack): CodeBlock => { | ||
const { | ||
rows: [head, ...body] | ||
} = pack | ||
const { indent = 0, text = '' } = head ?? {} | ||
const fileName: string = text.replace(/^\s*code:/, '') | ||
rows: [head, ...body], | ||
} = pack; | ||
const { indent = 0, text = "" } = head ?? {}; | ||
const fileName: string = text.replace(/^\s*code:/, ""); | ||
|
||
return { | ||
indent, | ||
type: 'codeBlock', | ||
type: "codeBlock", | ||
fileName, | ||
content: body.map((row: Row): string => row.text.substring(indent + 1)).join('\n') | ||
} | ||
} | ||
content: body | ||
.map((row: Row): string => row.text.substring(indent + 1)) | ||
.join("\n"), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import { convertToNodes } from './node' | ||
import { convertToNodes } from "./node"; | ||
|
||
import type { Row } from './Row' | ||
import type { Node } from './node/type' | ||
import type { Row } from "./Row"; | ||
import type { Node } from "./node/type"; | ||
|
||
export interface LinePack { | ||
type: 'line' | ||
rows: [Row] | ||
type: "line"; | ||
rows: [Row]; | ||
} | ||
|
||
export interface Line { | ||
indent: number | ||
type: 'line' | ||
nodes: Node[] | ||
indent: number; | ||
type: "line"; | ||
nodes: Node[]; | ||
} | ||
|
||
export const convertToLine = (pack: LinePack): Line => { | ||
const { indent, text } = pack.rows[0] | ||
const { indent, text } = pack.rows[0]; | ||
return { | ||
indent, | ||
type: 'line', | ||
nodes: convertToNodes(text.substring(indent)) | ||
} | ||
} | ||
type: "line", | ||
nodes: convertToNodes(text.substring(indent)), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,47 @@ | ||
import type { ParserOption } from '../parse' | ||
import type { CodeBlockPack } from './CodeBlock' | ||
import type { LinePack } from './Line' | ||
import type { Row } from './Row' | ||
import type { TablePack } from './Table' | ||
import type { TitlePack } from './Title' | ||
import type { ParserOption } from "../parse"; | ||
import type { CodeBlockPack } from "./CodeBlock"; | ||
import type { LinePack } from "./Line"; | ||
import type { Row } from "./Row"; | ||
import type { TablePack } from "./Table"; | ||
import type { TitlePack } from "./Title"; | ||
|
||
export type Pack = TitlePack | CodeBlockPack | TablePack | LinePack | ||
export type Pack = TitlePack | CodeBlockPack | TablePack | LinePack; | ||
|
||
const isChildRowOfPack = (pack: Pack, row: Row): boolean => | ||
(pack.type === 'codeBlock' || pack.type === 'table') && row.indent > (pack.rows[0]?.indent ?? 0) | ||
(pack.type === "codeBlock" || pack.type === "table") && | ||
row.indent > (pack.rows[0]?.indent ?? 0); | ||
|
||
const packing = (packs: Pack[], row: Row): Pack[] => { | ||
const lastPack = packs[packs.length - 1] | ||
const lastPack = packs[packs.length - 1]; | ||
if (lastPack !== undefined && isChildRowOfPack(lastPack, row)) { | ||
lastPack.rows.push(row) | ||
return packs | ||
lastPack.rows.push(row); | ||
return packs; | ||
} | ||
|
||
packs.push({ | ||
type: /^\s*code:/.test(row.text) ? 'codeBlock' : /^\s*table:/.test(row.text) ? 'table' : 'line', | ||
rows: [row] | ||
}) | ||
type: /^\s*code:/.test(row.text) | ||
? "codeBlock" | ||
: /^\s*table:/.test(row.text) | ||
? "table" | ||
: "line", | ||
rows: [row], | ||
}); | ||
|
||
return packs | ||
} | ||
return packs; | ||
}; | ||
|
||
export const packRows = (rows: Row[], opts: ParserOption): Pack[] => { | ||
if (opts.hasTitle ?? true) { | ||
const [title, ...body] = rows | ||
if (title === undefined) return [] | ||
const [title, ...body] = rows; | ||
if (title === undefined) return []; | ||
return [ | ||
{ | ||
type: 'title', | ||
rows: [title] | ||
type: "title", | ||
rows: [title], | ||
}, | ||
...body.reduce(packing, []) | ||
] | ||
...body.reduce(packing, []), | ||
]; | ||
} | ||
|
||
return rows.reduce(packing, []) | ||
} | ||
return rows.reduce(packing, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
export interface Row { | ||
indent: number | ||
text: string | ||
indent: number; | ||
text: string; | ||
} | ||
|
||
export const parseToRows = (input: string): Row[] => | ||
input.split('\n').map(text => ({ | ||
input.split("\n").map((text) => ({ | ||
indent: /^\s+/.exec(text)?.[0]?.length ?? 0, | ||
text | ||
})) | ||
text, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,39 @@ | ||
import { convertToNodes } from './node' | ||
import { convertToNodes } from "./node"; | ||
|
||
import type { Row } from './Row' | ||
import type { Node } from './node/type' | ||
import type { Row } from "./Row"; | ||
import type { Node } from "./node/type"; | ||
|
||
export interface TablePack { | ||
type: 'table' | ||
rows: Row[] | ||
type: "table"; | ||
rows: Row[]; | ||
} | ||
|
||
export interface Table { | ||
indent: number | ||
type: 'table' | ||
fileName: string | ||
cells: Node[][][] | ||
indent: number; | ||
type: "table"; | ||
fileName: string; | ||
cells: Node[][][]; | ||
} | ||
|
||
export const convertToTable = (pack: TablePack): Table => { | ||
const { | ||
rows: [head, ...body] | ||
} = pack | ||
const { indent = 0, text = '' } = head ?? {} | ||
const fileName = text.replace(/^\s*table:/, '') | ||
rows: [head, ...body], | ||
} = pack; | ||
const { indent = 0, text = "" } = head ?? {}; | ||
const fileName = text.replace(/^\s*table:/, ""); | ||
|
||
return { | ||
indent, | ||
type: 'table', | ||
type: "table", | ||
fileName, | ||
cells: body | ||
.map((row: Row): string => row.text.substring(indent + 1)) | ||
.map((text: string): Node[][] => | ||
text | ||
.split('\t') | ||
.map((block: string): Node[] => convertToNodes(block, { nested: true, quoted: false })) | ||
) | ||
} | ||
} | ||
.split("\t") | ||
.map((block: string): Node[] => | ||
convertToNodes(block, { nested: true, quoted: false }) | ||
) | ||
), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import type { Row } from './Row' | ||
import type { Row } from "./Row"; | ||
|
||
export interface TitlePack { | ||
type: 'title' | ||
rows: [Row] | ||
type: "title"; | ||
rows: [Row]; | ||
} | ||
|
||
export interface Title { | ||
type: 'title' | ||
text: string | ||
type: "title"; | ||
text: string; | ||
} | ||
|
||
export const convertToTitle = (pack: TitlePack): Title => { | ||
return { | ||
type: 'title', | ||
text: pack.rows[0].text | ||
} | ||
} | ||
type: "title", | ||
text: pack.rows[0].text, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import { convertToTitle } from './Title' | ||
import { convertToCodeBlock } from './CodeBlock' | ||
import { convertToTable } from './Table' | ||
import { convertToLine } from './Line' | ||
import { convertToTitle } from "./Title"; | ||
import { convertToCodeBlock } from "./CodeBlock"; | ||
import { convertToTable } from "./Table"; | ||
import { convertToLine } from "./Line"; | ||
|
||
import type { Pack } from './Pack' | ||
import type { Title } from './Title' | ||
import type { CodeBlock } from './CodeBlock' | ||
import type { Table } from './Table' | ||
import type { Line } from './Line' | ||
import type { Pack } from "./Pack"; | ||
import type { Title } from "./Title"; | ||
import type { CodeBlock } from "./CodeBlock"; | ||
import type { Table } from "./Table"; | ||
import type { Line } from "./Line"; | ||
|
||
export type Block = Title | CodeBlock | Table | Line | ||
export type Block = Title | CodeBlock | Table | Line; | ||
|
||
export const convertToBlock = (pack: Pack): Block => { | ||
switch (pack.type) { | ||
case 'title': | ||
return convertToTitle(pack) | ||
case "title": | ||
return convertToTitle(pack); | ||
|
||
case 'codeBlock': | ||
return convertToCodeBlock(pack) | ||
case "codeBlock": | ||
return convertToCodeBlock(pack); | ||
|
||
case 'table': | ||
return convertToTable(pack) | ||
case "table": | ||
return convertToTable(pack); | ||
|
||
case 'line': | ||
return convertToLine(pack) | ||
case "line": | ||
return convertToLine(pack); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import { createNodeParser } from './creator' | ||
import { createNodeParser } from "./creator"; | ||
|
||
import type { BlankNode } from './type' | ||
import type { NodeCreator } from './creator' | ||
import type { BlankNode } from "./type"; | ||
import type { NodeCreator } from "./creator"; | ||
|
||
const blankRegExp = /\[\s+\]/ | ||
const blankRegExp = /\[\s+\]/; | ||
|
||
const createBlankNode: NodeCreator<BlankNode> = (raw: string) => ({ | ||
type: 'blank', | ||
type: "blank", | ||
raw, | ||
text: raw.substring(1, raw.length - 1) | ||
}) | ||
text: raw.substring(1, raw.length - 1), | ||
}); | ||
|
||
export const BlankNodeParser = createNodeParser(createBlankNode, { | ||
parseOnNested: false, | ||
parseOnQuoted: true, | ||
patterns: [blankRegExp] | ||
}) | ||
patterns: [blankRegExp], | ||
}); |
Oops, something went wrong.