INNER CODE UNIT · JavaScript

stripMarkdown

rockbenben/ChatGPT-Shortcut · plugin-gen-geo.js:75

function stripMarkdown(text) {
  if (!text) return "";
  return text
    .replace(/^#+\s+/gm, "") // headings
    .replace(/(\*\*|__)(.*?)\1/g, "$2") // bold
    .replace(/(\*|_)(.*?)\1/g, "$2") // italic
    .replace(/\[([^\]]+)\]\(([^)]+)\)/g, "$1") // links
    .replace(/`([^`]+)`/g, "$1") // code
    .replace(/^\s*-\s+/gm, "") // list items
    .replace(/^\s*>\s+/gm, "") // blockquotes
    .replace(/\n+/g, " ") // newlines to spaces
    .trim();
}

// 智能截断:在最近的句子结束符处切,避免截在词中间
// 优先级:中文句号/问号/感叹号 > 英文句号/问号/感叹号 > 分号 > 逗号 > 空格
function smartTruncate(text, maxLen) {
  if (!text || text.length <= maxLen) return text;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…