mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-03-28 23:08:12 +00:00
final fixes
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint max-lines: ["error", { "max": 400 }] */
|
||||||
import './codeEditor.less';
|
import './codeEditor.less';
|
||||||
import React, { useEffect, useRef, forwardRef, useImperativeHandle } from 'react';
|
import React, { useEffect, useRef, forwardRef, useImperativeHandle } from 'react';
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ import { languages } from '@codemirror/language-data';
|
|||||||
import { css } from '@codemirror/lang-css';
|
import { css } from '@codemirror/lang-css';
|
||||||
import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
|
import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
|
||||||
import { autocompleteEmoji } from './autocompleteEmoji.js';
|
import { autocompleteEmoji } from './autocompleteEmoji.js';
|
||||||
import { searchKeymap, highlightSelectionMatches, search, openSearchPanel } from '@codemirror/search';
|
import { searchKeymap, search } from '@codemirror/search';
|
||||||
|
|
||||||
import * as themes from '@uiw/codemirror-themes-all';
|
import * as themes from '@uiw/codemirror-themes-all';
|
||||||
const themeCompartment = new Compartment();
|
const themeCompartment = new Compartment();
|
||||||
@@ -32,7 +33,7 @@ import { legacyCustomHighlightStyle, legacyTokenizeCustomMarkdown } from './lega
|
|||||||
|
|
||||||
const createHighlightPlugin = (renderer, tab)=>{
|
const createHighlightPlugin = (renderer, tab)=>{
|
||||||
const tokenize = renderer === 'V3' ? tokenizeCustomMarkdown : legacyTokenizeCustomMarkdown;
|
const tokenize = renderer === 'V3' ? tokenizeCustomMarkdown : legacyTokenizeCustomMarkdown;
|
||||||
|
/* eslint-disable no-restricted-syntax */
|
||||||
class countWidget extends WidgetType {
|
class countWidget extends WidgetType {
|
||||||
constructor(count) {
|
constructor(count) {
|
||||||
super();
|
super();
|
||||||
@@ -47,6 +48,7 @@ const createHighlightPlugin = (renderer, tab)=>{
|
|||||||
}
|
}
|
||||||
ignoreEvent() { return true; }
|
ignoreEvent() { return true; }
|
||||||
}
|
}
|
||||||
|
/* eslint-enable no-restricted-syntax */
|
||||||
|
|
||||||
return ViewPlugin.fromClass(
|
return ViewPlugin.fromClass(
|
||||||
class {
|
class {
|
||||||
|
|||||||
@@ -15,17 +15,13 @@ const customTags = {
|
|||||||
definitionList : 'definitionList', // .cm-definitionList
|
definitionList : 'definitionList', // .cm-definitionList
|
||||||
definitionTerm : 'definitionTerm', // .cm-definitionTerm
|
definitionTerm : 'definitionTerm', // .cm-definitionTerm
|
||||||
definitionDesc : 'definitionDesc', // .cm-definitionDesc
|
definitionDesc : 'definitionDesc', // .cm-definitionDesc
|
||||||
definitionColon : 'definitionColon',// .cm-definitionColon
|
definitionColon : 'definitionColon', // .cm-definitionColon
|
||||||
};
|
};
|
||||||
|
|
||||||
export function tokenizeCustomMarkdown(text) {
|
export function tokenizeCustomMarkdown(text) {
|
||||||
const tokens = [];
|
const tokens = [];
|
||||||
const lines = text.split('\n');
|
const lines = text.split('\n');
|
||||||
|
|
||||||
// Track multi-line blocks
|
|
||||||
const inBlock = false;
|
|
||||||
const blockStart = 0;
|
|
||||||
|
|
||||||
lines.forEach((lineText, lineNumber)=>{
|
lines.forEach((lineText, lineNumber)=>{
|
||||||
// --- Page / snippet lines ---
|
// --- Page / snippet lines ---
|
||||||
if(/^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m.test(lineText)) tokens.push({ line: lineNumber, type: customTags.pageLine });
|
if(/^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m.test(lineText)) tokens.push({ line: lineNumber, type: customTags.pageLine });
|
||||||
@@ -92,7 +88,6 @@ export function tokenizeCustomMarkdown(text) {
|
|||||||
if(match) {
|
if(match) {
|
||||||
const [full, term, colons, desc] = match;
|
const [full, term, colons, desc] = match;
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
|
|
||||||
// Entire line as definitionList
|
// Entire line as definitionList
|
||||||
tokens.push({
|
tokens.push({
|
||||||
line : lineNumber,
|
line : lineNumber,
|
||||||
@@ -131,7 +126,6 @@ export function tokenizeCustomMarkdown(text) {
|
|||||||
|
|
||||||
// multiline def list
|
// multiline def list
|
||||||
if(!/^::/.test(lines[lineNumber]) && lineNumber + 1 < lines.length && /^::/.test(lines[lineNumber + 1])) {
|
if(!/^::/.test(lines[lineNumber]) && lineNumber + 1 < lines.length && /^::/.test(lines[lineNumber + 1])) {
|
||||||
const term = lineText;
|
|
||||||
const startLine = lineNumber;
|
const startLine = lineNumber;
|
||||||
const defs = [];
|
const defs = [];
|
||||||
let endLine = startLine;
|
let endLine = startLine;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint max-lines: ["error", { "max": 300 }] */
|
||||||
import { keymap } from '@codemirror/view';
|
import { keymap } from '@codemirror/view';
|
||||||
import { undo, redo } from '@codemirror/commands';
|
import { undo, redo } from '@codemirror/commands';
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { HighlightStyle } from '@codemirror/language';
|
import { HighlightStyle } from '@codemirror/language';
|
||||||
import { tags } from '@lezer/highlight';
|
import { tags } from '@lezer/highlight';
|
||||||
|
|
||||||
// Making the tokens
|
|
||||||
const customTags = {
|
const customTags = {
|
||||||
pageLine : 'pageLine', // .cm-pageLine
|
pageLine : 'pageLine', // .cm-pageLine
|
||||||
snippetLine : 'snippetLine', // .cm-snippetLine
|
snippetLine : 'snippetLine', // .cm-snippetLine
|
||||||
@@ -11,10 +10,6 @@ export function legacyTokenizeCustomMarkdown(text) {
|
|||||||
const tokens = [];
|
const tokens = [];
|
||||||
const lines = text.split('\n');
|
const lines = text.split('\n');
|
||||||
|
|
||||||
// Track multi-line blocks
|
|
||||||
const inBlock = false;
|
|
||||||
const blockStart = 0;
|
|
||||||
|
|
||||||
lines.forEach((lineText, lineNumber)=>{
|
lines.forEach((lineText, lineNumber)=>{
|
||||||
// --- Page / snippet lines ---
|
// --- Page / snippet lines ---
|
||||||
if(/^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m.test(lineText)) tokens.push({ line: lineNumber, type: customTags.pageLine });
|
if(/^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m.test(lineText)) tokens.push({ line: lineNumber, type: customTags.pageLine });
|
||||||
@@ -31,4 +26,3 @@ export const legacyCustomHighlightStyle = HighlightStyle.define([
|
|||||||
{ tag: customTags.snippetLine, class: 'cm-snippetLine', color: '#0af' },
|
{ tag: customTags.snippetLine, class: 'cm-snippetLine', color: '#0af' },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import React from 'react';
|
|||||||
import createReactClass from 'create-react-class';
|
import createReactClass from 'create-react-class';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import dedent from 'dedent';
|
import dedent from 'dedent';
|
||||||
import Markdown from '@shared/markdown.js';
|
|
||||||
|
|
||||||
import CodeEditor from '../../components/codeEditor/codeEditor.jsx';
|
import CodeEditor from '../../components/codeEditor/codeEditor.jsx';
|
||||||
import SnippetBar from './snippetbar/snippetbar.jsx';
|
import SnippetBar from './snippetbar/snippetbar.jsx';
|
||||||
@@ -13,7 +12,7 @@ import MetadataEditor from './metadataEditor/metadataEditor.jsx';
|
|||||||
const EDITOR_THEME_KEY = 'HB_editor_theme';
|
const EDITOR_THEME_KEY = 'HB_editor_theme';
|
||||||
|
|
||||||
const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
||||||
const SNIPPETBREAK_REGEX_V3 = /^\\snippet\ .*$/;
|
//const SNIPPETBREAK_REGEX_V3 = /^\\snippet\ .*$/;
|
||||||
const DEFAULT_STYLE_TEXT = dedent`
|
const DEFAULT_STYLE_TEXT = dedent`
|
||||||
/*=======--- Example CSS styling ---=======*/
|
/*=======--- Example CSS styling ---=======*/
|
||||||
/* Any CSS here will apply to your document! */
|
/* Any CSS here will apply to your document! */
|
||||||
|
|||||||
Reference in New Issue
Block a user