@opencode/ui 0.0.0-dev-19417 → 0.0.0-dev-19420

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencode/ui",
3
- "version": "0.0.0-dev-19417",
3
+ "version": "0.0.0-dev-19420",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -16,7 +16,35 @@ let smallParser: Marked | undefined
16
16
  export function parseSmallMarkdown(text: string) {
17
17
  // Any possible KaTeX delimiter stays on the worker, including escaped ones.
18
18
  if (text.length > 1024 || text.includes("\\(") || text.includes("$$")) return
19
+ // Ordinary prose does not need the block/inline lexer's cold regular expressions.
20
+ // Keep every possible Markdown construct, autolink, and hard break on that lexer.
21
+ if (
22
+ /^[\p{L}\p{N} \t\r\n,.;:!?'"’“”()\-–—…$%]+$/u.test(text) &&
23
+ !/(?:^|[\r\n])(?:[ \t]|\d|[-])| {2}(?:\r\n?|\n)|www\./.test(text)
24
+ ) {
25
+ return text
26
+ .replace(/\r\n?/g, "\n")
27
+ .replace(/^\n+|\n+$/g, "")
28
+ .split(/\n{2,}/)
29
+ .filter(Boolean)
30
+ .map((paragraph) => `<p>${paragraph.replace(/["']/g, (value) => (value === '"' ? "&quot;" : "&#39;"))}</p>\n`)
31
+ .join("")
32
+ }
19
33
  const parser = (smallParser ??= createMarkdownBase())
34
+ const paragraphs = text.replace(/\r\n?/g, "\n")
35
+ // Inline formatting in ordinary paragraphs does not need the block lexer.
36
+ // Any possible block opener, HTML, table, or reference definition stays on it.
37
+ if (
38
+ !/[<|]/.test(paragraphs) &&
39
+ !/^(?:[ \t>\d\[\-=]|#{1,6}(?:[ \t]|$)|[`~]{3}|[+*](?:[ \t]|$)|(?:[*_][ \t]*){3,}$)/m.test(paragraphs)
40
+ ) {
41
+ return paragraphs
42
+ .replace(/^\n+|\n+$/g, "")
43
+ .split(/\n{2,}/)
44
+ .filter(Boolean)
45
+ .map((paragraph) => `<p>${parser.parseInline(paragraph, { async: false })}</p>\n`)
46
+ .join("")
47
+ }
20
48
  const tokens = parser.lexer(text)
21
49
  let code = false
22
50
  parser.walkTokens(tokens, (token) => {