mirror of
https://github.com/kotaindah55/extended-markdown-syntax.git
synced 2026-07-22 12:00:23 +00:00
refactor: reorganize folders and files
This commit is contained in:
parent
841ab04b78
commit
dd3ab6eb7a
81 changed files with 251 additions and 71 deletions
7
main.ts
7
main.ts
|
|
@ -5,7 +5,8 @@ import { ColorConfig, PluginSettings, TagConfig } from "src/types";
|
|||
import { DEFAULT_SETTINGS } from "src/settings";
|
||||
import { ExtendedSettingTab } from "src/settings/interface";
|
||||
import { pluginFacet, settingsFacet } from "src/editor-mode/facets";
|
||||
import { configureDelimLookup, deepCopy, reconfigureDelimLookup } from "src/utils";
|
||||
import { deepCopy } from "src/utils";
|
||||
import { configureDelimLookup, reconfigureDelimLookup, supportTag } from "src/format-configs/utils"
|
||||
import { appFacet } from "src/editor-mode/facets";
|
||||
import { editorExtendedSyntax } from "src/editor-mode/extensions";
|
||||
import { refresherAnnot } from "src/editor-mode/annotations";
|
||||
|
|
@ -70,7 +71,7 @@ export default class ExtendedMarkdownSyntax extends Plugin {
|
|||
buildColorsStyleSheet(callback?: (colorConfig: ColorConfig, colorConfigs: ColorConfig[]) => unknown) {
|
||||
let colorConfigs = this.settings.colorConfigs;
|
||||
for (let i = 0; i < colorConfigs.length; i++) {
|
||||
let ruleStr = createCSSRuleFromColorConfig(colorConfigs[i]);
|
||||
let ruleStr = convertColorConfigToCSSRule(colorConfigs[i]);
|
||||
this.colorsHandler.insert(ruleStr);
|
||||
if (callback) { callback(colorConfigs[i], colorConfigs) }
|
||||
}
|
||||
|
|
@ -91,7 +92,7 @@ export default class ExtendedMarkdownSyntax extends Plugin {
|
|||
addNewColor() {
|
||||
let index = this.settings.colorConfigs.length,
|
||||
newConfig = createColorConfig("color-" + index, "#ffd000", "Color " + index),
|
||||
ruleStr = createCSSRuleFromColorConfig(newConfig);
|
||||
ruleStr = convertColorConfigToCSSRule(newConfig);
|
||||
this.settings.colorConfigs.push(newConfig);
|
||||
this.colorsHandler.insert(ruleStr, index);
|
||||
}
|
||||
|
|
|
|||
1
src/color-management/PREDEFINED_COLOR_TAGS.ts
Normal file
1
src/color-management/PREDEFINED_COLOR_TAGS.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export const PREDEFINED_COLOR_TAGS = ["red", "orange", "yellow", "green", "cyan", "blue", "purple", "pink"] as const;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { ColorConfig } from "src/types";
|
||||
|
||||
export function createCSSRuleFromColorConfig(config: ColorConfig) {
|
||||
let selector = `.cm-custom-highlight-${config.tag}, .markdown-rendered mark.custom-highlight-${config.tag}, .menu-item-${config.tag}>.menu-item-title`,
|
||||
export function convertColorConfigToCSSRule(config: ColorConfig) {
|
||||
let selector = `.cm-custom-highlight-${config.tag}, .markdown-rendered mark.custom-highlight-${config.tag}, .ems-menu-item.ems-highlight-${config.tag}>.menu-item-title`,
|
||||
prop = "background-color",
|
||||
color = config.color;
|
||||
return `${selector}{${prop}:color(from ${color} srgb r g b/var(--hl-opacity));}`
|
||||
|
|
@ -1,13 +1,11 @@
|
|||
import { ColorConfig } from "src/types";
|
||||
import { takeBuiltinColor } from "src/color-management";
|
||||
import { takeBuiltinColor, PREDEFINED_COLOR_TAGS } from "src/color-management";
|
||||
|
||||
export function getDefaultColorConfigs() {
|
||||
let configs: ColorConfig[] = [],
|
||||
predefinedTags = ["red", "orange", "yellow", "green", "cyan", "blue", "purple", "pink"],
|
||||
predefinedNames = ["Red", "Orange", "Yellow", "Green", "Cyan", "Blue", "Purple", "Pink"];
|
||||
for (let i = 0; i < predefinedTags.length; i++) {
|
||||
let tag = predefinedTags[i],
|
||||
name = predefinedNames[i],
|
||||
let configs: ColorConfig[] = [];
|
||||
for (let i = 0; i < PREDEFINED_COLOR_TAGS.length; i++) {
|
||||
let tag = PREDEFINED_COLOR_TAGS[i],
|
||||
name = tag[0].toUpperCase() + tag.slice(1),
|
||||
color = takeBuiltinColor(tag) ?? "#ffffff";
|
||||
configs.push({ tag, name, color, showInMenu: true });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
export * from "./createCSSRuleFromColorConfig";
|
||||
export * from "./convertColorConfigToCSSRule";
|
||||
export * from "./takeBuiltinColor";
|
||||
export * from "./getDefaultColorConfigs";
|
||||
export * from "./createColorConfig";
|
||||
export * from "./createColorConfig";
|
||||
export * from "./PREDEFINED_COLOR_TAGS";
|
||||
|
|
@ -5,9 +5,12 @@ import { Format, MarkdownViewMode, TokenStatus } from "src/enums";
|
|||
import { REVEALED_SPOILER_DECO } from "src/editor-mode/decorator/decorations";
|
||||
import { BlockFormat, PlainRange, InlineFormat, Token, TokenGroup, TokenDecoration, PluginSettings } from "src/types";
|
||||
import { ColorButton } from "src/editor-mode/decorator/widgets";
|
||||
import { BlockRules, InlineRules } from "src/shared-configs";
|
||||
import { BlockRules, InlineRules } from "src/format-configs";
|
||||
import { DecorationHolder, DelimOmitter, LineBreakReplacer, TokensCatcher } from "src/editor-mode/decorator/builder";
|
||||
import { createInlineDecoRange, createLineDecoRange, getLineAt, getTagRange, isEditorModeChanged, iterLine, iterTokenGroup, sliceStrFromLine } from "src/editor-mode/decorator/utils";
|
||||
import { createInlineDecoRange, createLineDecoRange } from "src/editor-mode/decorator/decorator-utils";
|
||||
import { isEditorModeChanged } from "src/editor-mode/editor-utils";
|
||||
import { getLineAt, iterLine, sliceStrFromLine } from "src/editor-mode/doc-utils";
|
||||
import { getTagRange, iterTokenGroup } from "src/editor-mode/parser/token-utils"
|
||||
import { trimTag } from "src/utils";
|
||||
import { SelectionObserver } from "src/editor-mode/observer";
|
||||
import { editorLivePreviewField } from "obsidian";
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { RangeSet, Range, Text, ChangeSet } from "@codemirror/state";
|
|||
import { Decoration } from "@codemirror/view";
|
||||
import { Parser } from "src/editor-mode/parser";
|
||||
import { IndexCache, RangeSetUpdate, TokenGroup } from "src/types";
|
||||
import { getLineAt, iterLine } from "src/editor-mode/decorator/utils";
|
||||
import { getLineAt, iterLine } from "src/editor-mode/doc-utils";
|
||||
import { LineBreak } from "src/editor-mode/decorator/widgets";
|
||||
import { TokenLevel, TokenStatus } from "src/enums";
|
||||
|
||||
|
|
|
|||
3
src/editor-mode/decorator/decorator-utils/index.ts
Normal file
3
src/editor-mode/decorator/decorator-utils/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export * from "./createHlDeco";
|
||||
export * from "./createInlineDecoRange";
|
||||
export * from "./createLineDecoRange";
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
export * from "./createHlDeco";
|
||||
export * from "./createInlineDecoRange";
|
||||
export * from "./getLineAt";
|
||||
export * from "./sliceStrFromLine";
|
||||
export * from "./getTagRange";
|
||||
export * from "./createLineDecoRange";
|
||||
export * from "./iterLine";
|
||||
export * from "./iterTokenGroup";
|
||||
export * from "./moveTokenIndexCache";
|
||||
export * from "./isEditorModeChanged";
|
||||
14
src/editor-mode/doc-utils/getBlockEndAt.ts
Normal file
14
src/editor-mode/doc-utils/getBlockEndAt.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { Line, Text } from "@codemirror/state"
|
||||
import { isBlankLine } from "src/editor-mode/doc-utils";
|
||||
|
||||
export function getBlockEndAt(doc: Text, offsetOrLine: number | Line, blankLineAsEnd = true) {
|
||||
let line = offsetOrLine instanceof Line ? offsetOrLine : doc.lineAt(offsetOrLine);
|
||||
while (line.number < doc.lines) {
|
||||
line = doc.line(line.number + 1);
|
||||
if (isBlankLine(line)) {
|
||||
if (!blankLineAsEnd) { line = doc.line(line.number - 1) }
|
||||
break;
|
||||
}
|
||||
}
|
||||
return line;
|
||||
}
|
||||
14
src/editor-mode/doc-utils/getBlockStartAt.ts
Normal file
14
src/editor-mode/doc-utils/getBlockStartAt.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { Line, Text } from "@codemirror/state";
|
||||
import { isBlankLine } from "src/editor-mode/doc-utils";
|
||||
|
||||
export function getBlockStartAt(doc: Text, offsetOrLine: number | Line) {
|
||||
let curLine = offsetOrLine instanceof Line ? offsetOrLine : doc.lineAt(offsetOrLine),
|
||||
prevLine = curLine.number > 1 ? doc.line(curLine.number - 1) : null;
|
||||
if (isBlankLine(curLine)) { return curLine }
|
||||
while (prevLine) {
|
||||
if (isBlankLine(prevLine)) { break }
|
||||
curLine = prevLine;
|
||||
prevLine = curLine.number > 1 ? doc.line(curLine.number - 1) : null;
|
||||
}
|
||||
return curLine;
|
||||
}
|
||||
31
src/editor-mode/doc-utils/getBlockStarts.ts
Normal file
31
src/editor-mode/doc-utils/getBlockStarts.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { Line, Text } from "@codemirror/state";
|
||||
import { PlainRange } from "src/types";
|
||||
import { getBlockStartAt, isBlankLine } from "src/editor-mode/doc-utils";
|
||||
|
||||
export function getBlockStarts(doc: Text, range: PlainRange, lookBehind = true) {
|
||||
let curLine = doc.lineAt(range.from),
|
||||
nextLine = curLine.number <= doc.lines ? doc.line(curLine.number + 1) : null,
|
||||
curLineIsBlank = isBlankLine(curLine),
|
||||
blockStarts: Line[] = [];
|
||||
if (lookBehind) {
|
||||
blockStarts.push(getBlockStartAt(doc, curLine));
|
||||
} else {
|
||||
blockStarts.push(curLine);
|
||||
}
|
||||
while (nextLine) {
|
||||
if (isBlankLine(nextLine)) {
|
||||
curLineIsBlank = true;
|
||||
} else {
|
||||
if (curLineIsBlank) {
|
||||
blockStarts.push(nextLine);
|
||||
}
|
||||
curLineIsBlank = false;
|
||||
}
|
||||
curLine = nextLine;
|
||||
nextLine = curLine.number <= doc.lines ? doc.line(curLine.number + 1) : null;
|
||||
}
|
||||
if (blockStarts.length > 1 && isBlankLine(blockStarts[0])) {
|
||||
blockStarts.shift();
|
||||
}
|
||||
return blockStarts;
|
||||
}
|
||||
33
src/editor-mode/doc-utils/getBlocks.ts
Normal file
33
src/editor-mode/doc-utils/getBlocks.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { PlainRange } from "src/types";
|
||||
import { Text } from "@codemirror/state";
|
||||
import { getBlockStartAt } from "./getBlockStartAt";
|
||||
import { isBlankLine } from "./isBlankLine";
|
||||
import { getBlockEndAt } from "./getBlockEndAt";
|
||||
|
||||
export function getBlocks(doc: Text, range: PlainRange, lookBehind = false, lookAhead = false) {
|
||||
let blocks: { start: number, end: number }[] = [],
|
||||
line = doc.lineAt(range.from),
|
||||
initLine = line,
|
||||
curBlock: { start: number, end: number } | undefined;
|
||||
if (!isBlankLine(line) && lookBehind) {
|
||||
let blockStart = getBlockStartAt(doc, line);
|
||||
curBlock = { start: blockStart.number, end: line.number + 1 };
|
||||
blocks.push(curBlock);
|
||||
}
|
||||
for (; range.to >= line.from; line = doc.line(line.number + 1)) {
|
||||
if (isBlankLine(line)) { curBlock = undefined }
|
||||
else if (curBlock) { curBlock.end++ }
|
||||
else {
|
||||
curBlock = { start: line.number, end: line.number + 1 };
|
||||
blocks.push(curBlock);
|
||||
}
|
||||
if (line.number >= doc.lines) { break }
|
||||
}
|
||||
if (curBlock && lookAhead) {
|
||||
curBlock.end = getBlockEndAt(doc, line, false).number + 1;
|
||||
}
|
||||
if (!blocks.length) {
|
||||
blocks.push({ start: initLine.number, end: initLine.number + 1 });
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
import { IndexCache } from "src/types";
|
||||
import { Text } from "@codemirror/state"
|
||||
|
||||
export function getLineAt(doc: Text, offset: number, linePosCache: IndexCache) {
|
||||
export function getLineAt(doc: Text, offset: number, linePosCache?: IndexCache) {
|
||||
if (!linePosCache) { return doc.lineAt(offset) }
|
||||
if (linePosCache.number > doc.lines) { linePosCache.number = doc.lines }
|
||||
let curLine = doc.line(linePosCache.number);
|
||||
if (offset < curLine.from) {
|
||||
7
src/editor-mode/doc-utils/getNextLine.ts
Normal file
7
src/editor-mode/doc-utils/getNextLine.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { Line, Text } from "@codemirror/state";
|
||||
|
||||
export function getNextLine(doc: Text, offsetOrLine: number | Line) {
|
||||
let line = offsetOrLine instanceof Line ? offsetOrLine : doc.lineAt(offsetOrLine);
|
||||
if (line.number >= doc.lines) { return null }
|
||||
return doc.line(line.number + 1);
|
||||
}
|
||||
12
src/editor-mode/doc-utils/getPrevLine.ts
Normal file
12
src/editor-mode/doc-utils/getPrevLine.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { Line, Text } from "@codemirror/state";
|
||||
|
||||
export function getPrevLine(doc: Text, offsetOrLineNum: number | Line) {
|
||||
let lineNum: number;
|
||||
if (offsetOrLineNum instanceof Line) {
|
||||
lineNum = offsetOrLineNum.number;
|
||||
} else {
|
||||
lineNum = doc.lineAt(offsetOrLineNum).number;
|
||||
}
|
||||
if (lineNum <= 1) { return null }
|
||||
return doc.line(lineNum - 1);
|
||||
}
|
||||
12
src/editor-mode/doc-utils/index.ts
Normal file
12
src/editor-mode/doc-utils/index.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
export * from "./getBlockStartAt";
|
||||
export * from "./getBlockStarts";
|
||||
export * from "./getPrevLine";
|
||||
export * from "./getBlockEndAt";
|
||||
export * from "./isBlankLine";
|
||||
export * from "./sliceStrFromLine";
|
||||
export * from "./getLineAt";
|
||||
export * from "./iterLine";
|
||||
export * from "./getBlocks";
|
||||
export * from "./getNextLine";
|
||||
export * from "./isBlockStart";
|
||||
export * from "./isBlockEnd";
|
||||
8
src/editor-mode/doc-utils/isBlockEnd.ts
Normal file
8
src/editor-mode/doc-utils/isBlockEnd.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { Line, Text } from "@codemirror/state";
|
||||
import { getNextLine } from "./getNextLine";
|
||||
import { isBlankLine } from "./isBlankLine";
|
||||
|
||||
export function isBlockEnd(doc: Text, line: Line) {
|
||||
let nextLine = getNextLine(doc, line);
|
||||
return !nextLine || isBlankLine(nextLine);
|
||||
}
|
||||
8
src/editor-mode/doc-utils/isBlockStart.ts
Normal file
8
src/editor-mode/doc-utils/isBlockStart.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { Line, Text } from "@codemirror/state";
|
||||
import { getPrevLine } from "./getPrevLine";
|
||||
import { isBlankLine } from "./isBlankLine";
|
||||
|
||||
export function isBlockStart(doc: Text, line: Line) {
|
||||
let prevLine = getPrevLine(doc, line);
|
||||
return !prevLine || isBlankLine(prevLine);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { App } from "obsidian";
|
||||
import { isCanvas } from "src/editor-mode/utils";
|
||||
import { isCanvas } from "src/editor-mode/editor-utils";
|
||||
|
||||
export function getActiveCanvasEditor(app: App) {
|
||||
if (isCanvas(app)) {
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
export * from "./checkRefreshed";
|
||||
export * from "./getActiveCanvasNodeCoords";
|
||||
export * from "./getActiveCanvasEditor";
|
||||
export * from "./isCanvas";
|
||||
export * from "./isCanvas";
|
||||
export * from "./isEditorModeChanged";
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
import { TokenLevel } from "src/enums";
|
||||
import { Format, TokenLevel } from "src/enums";
|
||||
import { IndexCache, PlainRange, Region, Token, TokenGroup } from "src/types";
|
||||
import { Parser } from "src/editor-mode/parser";
|
||||
import { EditorSelection } from "@codemirror/state";
|
||||
import { joinRegions } from "src/editor-mode/observer/utils";
|
||||
import { joinRegions } from "src/editor-mode/range-utils";
|
||||
import { isInlineFormat } from "src/format-configs/utils";
|
||||
|
||||
/**
|
||||
* Appliance for managing selection-based decorations that are tied to
|
||||
|
|
@ -21,9 +22,15 @@ export class SelectionObserver {
|
|||
[TokenLevel.INLINE]: [],
|
||||
[TokenLevel.BLOCK]: []
|
||||
};
|
||||
/**
|
||||
* Mapped indexes of tokens to each index of corresponding selection that
|
||||
* is touched by them. For example, `maps[0]` contains all indexes of
|
||||
* tokens that touched the first selection. May be empty if corresponding
|
||||
* selection wasn't touched by any token.
|
||||
*/
|
||||
maps: Partial<Record<TokenLevel, number[]>>[] = [];
|
||||
/**
|
||||
* All selection-based decorations, eg. omitted delimiters, that are
|
||||
* All selection-based decorations, e.g. omitted delimiters, that are
|
||||
* associated with these tokens should be redrawn.
|
||||
*/
|
||||
changedRegions: Record<TokenLevel, Region> = {
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@ import { ParserState, TokenQueue } from "src/editor-mode/parser";
|
|||
import { ChangeSet, Line, Text } from "@codemirror/state";
|
||||
import { Format, MarkdownViewMode, TokenLevel } from "src/enums";
|
||||
import { Tokenizer } from "src/editor-mode/parser";
|
||||
import { Formats } from "src/shared-configs";
|
||||
import { Formats } from "src/format-configs";
|
||||
import { Tree } from "@lezer/common";
|
||||
import { composeChanges, disableEscape, findShifterAt, getBlockEndAt, getShifterStart, hasInterferer, provideTokenRanges, reenableEscape } from "src/editor-mode/parser/utils";
|
||||
import { composeChanges, disableEscape, findShifterAt, getShifterStart, hasInterferer, reenableEscape } from "src/editor-mode/parser/parser-utils";
|
||||
import { provideTokenRanges } from "src/editor-mode/parser/token-utils"
|
||||
import { EditorDelimLookup } from "src/editor-mode/parser/configs";
|
||||
import { colorTag, customSpanTag, fencedDivTag } from "src/editor-mode/parser/tokenizer-components";
|
||||
import { getBlockEndAt } from "src/editor-mode/doc-utils"
|
||||
|
||||
export class Parser {
|
||||
private state: ParserState;
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@ import { Tree, TreeCursor } from "@lezer/common";
|
|||
import { PluginSettings, StateConfig, TokenGroup } from "src/types";
|
||||
import { TokenQueue } from "src/editor-mode/parser";
|
||||
import { Format, LineCtx } from "src/enums";
|
||||
import { Formats } from "src/shared-configs";
|
||||
import { Formats } from "src/format-configs";
|
||||
import { SKIPPED_NODE_RE } from "src/editor-mode/parser/regexps";
|
||||
import { findNode, getContextFromNode, isBlankLine } from "src/editor-mode/parser/utils";
|
||||
import { findNode, getContextFromNode } from "src/editor-mode/parser/parser-utils";
|
||||
import { isBlankLine } from "src/editor-mode/doc-utils";
|
||||
|
||||
export class ParserState {
|
||||
doc: Text;
|
||||
|
|
@ -108,8 +109,8 @@ export class ParserState {
|
|||
}
|
||||
this.line = this.doc.line(this.linePos + 1);
|
||||
this.offset = 0;
|
||||
this.resolveContext();
|
||||
this.blkStart = false;
|
||||
this.resolveContext();
|
||||
if (skipBlankLine) {
|
||||
this.trySkipBlankLine();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Format, TokenLevel, TokenStatus } from "src/enums";
|
||||
import { InlineFormat, Token } from "src/types";
|
||||
import { ParserState } from "src/editor-mode/parser";
|
||||
import { Formats, InlineRules } from "src/shared-configs";
|
||||
import { Formats, InlineRules } from "src/format-configs";
|
||||
|
||||
/**
|
||||
* A place storing token based on its type, to be resolved through
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Format, TokenLevel, Delimiter, TokenStatus } from "src/enums";
|
||||
import { ParserState } from "src/editor-mode/parser";
|
||||
import { BlockFormat, InlineFormat, Token } from "src/types";
|
||||
import { handleClosingDelim, retrieveDelimSpec, validateDelim } from "src/editor-mode/parser/utils";
|
||||
import { handleClosingDelim, retrieveDelimSpec, validateDelim } from "src/editor-mode/parser/parser-utils";
|
||||
import { colorTag, customSpanTag, fencedDivTag } from "src/editor-mode/parser/tokenizer-components";
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { SyntaxNode, Tree } from "@lezer/common";
|
||||
import { SEMANTIC_INTERFERER_RE } from "src/editor-mode/parser/regexps";
|
||||
import { findNode } from "src/editor-mode/parser/utils";
|
||||
import { findNode } from "src/editor-mode/parser/parser-utils";
|
||||
|
||||
export function hasInterferer(tree: Tree, from: number, to: number) {
|
||||
let matcher = (node: SyntaxNode) => {
|
||||
|
|
@ -7,10 +7,7 @@ export * from "./hasInterferer";
|
|||
export * from "./retrieveDelimSpec";
|
||||
export * from "./validateDelim";
|
||||
export * from "./disableEscape";
|
||||
export * from "./isBlankLine";
|
||||
export * from "./isAlphanumeric";
|
||||
export * from "./measureIndent";
|
||||
export * from "./provideTokenRanges";
|
||||
export * from "./handleClosingDelim";
|
||||
export * from "./getBlockEndAt";
|
||||
export * from "./reenableEscape";
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { Delimiter, Format } from "src/enums";
|
||||
import { DelimSpec } from "src/types";
|
||||
import { BlockRules, InlineRules } from "src/shared-configs";
|
||||
import { isInlineFormat } from "src/utils";
|
||||
import { BlockRules, InlineRules } from "src/format-configs";
|
||||
import { isInlineFormat } from "src/format-configs/utils";
|
||||
|
||||
export function retrieveDelimSpec(type: Format, role: Delimiter): DelimSpec {
|
||||
let char: string, length: number, exactLen: boolean, allowSpaceOnDelim: boolean;
|
||||
5
src/editor-mode/parser/token-utils/index.ts
Normal file
5
src/editor-mode/parser/token-utils/index.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export * from "./iterTokenGroup";
|
||||
export * from "./moveTokenIndexCache";
|
||||
export * from "./provideTokenRanges";
|
||||
export * from "./isToken";
|
||||
export * from "./getTagRange";
|
||||
6
src/editor-mode/parser/token-utils/isToken.ts
Normal file
6
src/editor-mode/parser/token-utils/isToken.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { PlainRange, Token } from "src/types";
|
||||
|
||||
export function isToken(range: PlainRange): range is Token {
|
||||
let { type, openLen, tagLen, closeLen } = range as Token;
|
||||
return type !== undefined && openLen !== undefined && tagLen !== undefined && closeLen !== undefined;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { IterTokenGroupSpec } from "src/types";
|
||||
import { moveTokenIndexCache } from "src/editor-mode/decorator/utils";
|
||||
import { moveTokenIndexCache } from "src/editor-mode/parser/token-utils";
|
||||
|
||||
export function iterTokenGroup(spec: IterTokenGroupSpec) {
|
||||
let { tokens, ranges, callback, indexCache } = spec;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { isAlphanumeric } from "src/editor-mode/parser/utils";
|
||||
import { isAlphanumeric } from "src/editor-mode/parser/parser-utils";
|
||||
import { Token } from "src/types";
|
||||
import { ParserState } from "src/editor-mode/parser";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Token } from "src/types";
|
||||
import { ParserState } from "src/editor-mode/parser";
|
||||
import { isAlphanumeric } from "src/editor-mode/parser/utils";
|
||||
import { isAlphanumeric } from "src/editor-mode/parser/parser-utils";
|
||||
|
||||
export function customSpanTag(state: ParserState, token: Token) {
|
||||
let offset = state.offset,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { isAlphanumeric } from "src/editor-mode/parser/utils";
|
||||
import { isAlphanumeric } from "src/editor-mode/parser/parser-utils";
|
||||
import { Token } from "src/types";
|
||||
import { ParserState } from "src/editor-mode/parser";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
import { Text } from "@codemirror/state"
|
||||
import { isBlankLine } from "src/editor-mode/parser/utils";
|
||||
|
||||
export function getBlockEndAt(doc: Text, offset: number) {
|
||||
let line = doc.lineAt(offset);
|
||||
while (line.number < doc.lines) {
|
||||
line = doc.line(line.number + 1);
|
||||
if (isBlankLine(line)) { break }
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
export * from "./isTouched";
|
||||
export * from "./joinRegions";
|
||||
export * from "./separateRegions";
|
||||
5
src/editor-mode/range-utils/isTouched.ts
Normal file
5
src/editor-mode/range-utils/isTouched.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { PlainRange } from "src/types";
|
||||
|
||||
export function isTouched(offset: number, range: PlainRange) {
|
||||
return offset >= range.from && offset <= range.to;
|
||||
}
|
||||
2
src/editor-mode/selection/index.ts
Normal file
2
src/editor-mode/selection/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export * from "./trimSelection";
|
||||
export * from "./trimSelectionRange";
|
||||
10
src/editor-mode/selection/trimSelection.ts
Normal file
10
src/editor-mode/selection/trimSelection.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { EditorSelection, Text } from "@codemirror/state";
|
||||
import { trimSelectionRange } from "src/editor-mode/selection";
|
||||
|
||||
export function trimSelection(selection: EditorSelection, doc: Text) {
|
||||
for (let i = 0; i < selection.ranges.length; i++) {
|
||||
let trimmed = trimSelectionRange(selection.ranges[i], doc);
|
||||
selection = selection.replaceRange(trimmed, i);
|
||||
}
|
||||
return selection;
|
||||
}
|
||||
11
src/editor-mode/selection/trimSelectionRange.ts
Normal file
11
src/editor-mode/selection/trimSelectionRange.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { EditorSelection, SelectionRange, Text } from "@codemirror/state";
|
||||
|
||||
export function trimSelectionRange(range: SelectionRange, doc: Text): SelectionRange {
|
||||
let str = doc.sliceString(range.from, range.to),
|
||||
preSpaceLen = str.length - str.trimStart().length,
|
||||
postSpaceLen = str.length - str.trimEnd().length;
|
||||
if (str.length == preSpaceLen) {
|
||||
return EditorSelection.cursor(range.from);
|
||||
}
|
||||
return EditorSelection.range(range.from + preSpaceLen, range.to - postSpaceLen);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { Format } from "src/enums";
|
||||
import { BlockRules, InlineRules } from "src/shared-configs";
|
||||
import { BlockRules, InlineRules } from "src/format-configs";
|
||||
import { BlockFormat, InlineFormat } from "src/types";
|
||||
|
||||
export const Formats = {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { Format, MarkdownViewMode } from "src/enums";
|
||||
import { InlineRules } from "src/shared-configs";
|
||||
import { InlineRules } from "src/format-configs";
|
||||
import { PluginSettings } from "src/types";
|
||||
import { EditorDelimLookup } from "src/editor-mode/parser/configs";
|
||||
import { PreviewDelimLookup } from "src/preview-mode/configs";
|
||||
4
src/format-configs/utils/index.ts
Normal file
4
src/format-configs/utils/index.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export * from "./supportTag";
|
||||
export * from "./isInlineFormat";
|
||||
export * from "./configureDelimLookup";
|
||||
export * from "./reconfigureDelimLookup";
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { EditorDelimLookup } from "src/editor-mode/parser/configs";
|
||||
import { PreviewDelimLookup } from "src/preview-mode/configs";
|
||||
import { configureDelimLookup } from "src/utils";
|
||||
import { configureDelimLookup } from "src/format-configs/utils";
|
||||
import { PluginSettings } from "src/types";
|
||||
|
||||
export function reconfigureDelimLookup(settings: PluginSettings) {
|
||||
5
src/format-configs/utils/supportTag.ts
Normal file
5
src/format-configs/utils/supportTag.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { Format } from "src/enums";
|
||||
|
||||
export function supportTag(type: Format): type is Format.HIGHLIGHT | Format.CUSTOM_SPAN | Format.FENCED_DIV {
|
||||
return type >= Format.HIGHLIGHT || type == Format.FENCED_DIV;
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { Formats, InlineRules } from "src/shared-configs";
|
||||
import { Formats, InlineRules } from "src/format-configs";
|
||||
import { Format } from "src/enums";
|
||||
import { InlineFormat } from "src/types";
|
||||
import { SKIPPED_CLASSES, PreviewDelimLookup } from "src/preview-mode/configs";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { InlineRules } from "src/shared-configs";
|
||||
import { InlineRules } from "src/format-configs";
|
||||
import { COLOR_TAG_RE } from "src/preview-mode/regexp";
|
||||
import { Format } from "src/enums";
|
||||
import { PluginSettings } from "src/types";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Format } from "src/enums";
|
||||
import { CUSTOM_SPAN_TAG_RE } from "src/preview-mode/regexp";
|
||||
import { InlineRules } from "src/shared-configs";
|
||||
import { InlineRules } from "src/format-configs";
|
||||
import { PluginSettings } from "src/types";
|
||||
import { trimTag } from "src/utils";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { trimTag } from "src/utils";
|
||||
import { FENCED_DIV } from "src/preview-mode/regexp";
|
||||
import { BlockRules } from "src/shared-configs";
|
||||
import { BlockRules } from "src/format-configs";
|
||||
import { Format, MarkdownViewMode } from "src/enums";
|
||||
import { PluginSettings } from "src/types";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
export * from "./configureDelimLookup";
|
||||
export * from "./isInlineFormat";
|
||||
export * from "./trimTag";
|
||||
export * from "./reconfigureDelimLookup";
|
||||
export * from "./deepCopy";
|
||||
export * from "./moveElement";
|
||||
export * from "./getTheme";
|
||||
|
|
|
|||
Loading…
Reference in a new issue