mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
* fix: Pasting a table from Google Sheets does not create a table Spreadsheet cells containing currency amounts caused isMarkdown to misread the tab-separated plain text flavour of the clipboard as inline LaTeX, so the paste handler discarded the HTML table and reparsed the text as Markdown. Tighten the LaTeX heuristic to require delimiters that hug their content and a closing delimiter not followed by a digit, and always prefer the HTML parser when the clipboard HTML contains a table. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Remove lookbehind in regex --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
export default function isMarkdown(text: string): boolean {
|
|
let signals = 0;
|
|
const lines = text.split("\n").length;
|
|
const minConfidence = Math.min(3, Math.floor(lines / 5));
|
|
|
|
// code-ish
|
|
const fences = text.match(/^```/gm);
|
|
if (fences && fences.length > 1) {
|
|
signals += fences.length;
|
|
}
|
|
|
|
// latex-ish, the delimiters must hug their content and the closing one must
|
|
// not be followed by a digit so that currency amounts are not counted.
|
|
const latex = text.match(/\$[^\s](?:.*?[^\s])?\$(?!\d)/g);
|
|
if (latex && latex.length > 0) {
|
|
signals += latex.length;
|
|
}
|
|
|
|
// link-ish
|
|
const links = text.match(/\[[^]+\]\(https?:\/\/\S+\)/gm);
|
|
if (links) {
|
|
signals += links.length * 2;
|
|
}
|
|
|
|
const relativeLinks = text.match(/\[[^]+\]\(\/\S+\)/gm);
|
|
if (relativeLinks) {
|
|
signals += relativeLinks.length * 2;
|
|
}
|
|
|
|
// heading-ish
|
|
const headings = text.match(/^#{1,6}\s+\S+/gm);
|
|
if (headings) {
|
|
signals += headings.length;
|
|
}
|
|
|
|
// list-ish
|
|
const listItems = text.match(/^[-*]\s\S+/gm);
|
|
if (listItems) {
|
|
signals += listItems.length;
|
|
}
|
|
|
|
// table header-ish
|
|
const tables = text.match(/\|\s?[:-]+\s?\|/gm);
|
|
if (tables) {
|
|
signals += tables.length;
|
|
}
|
|
|
|
return signals > minConfidence;
|
|
}
|