Files
gochat/frontend/app/javascript/shared/helpers/markdownIt/link.js
T
rogee 321c61aaae Vendor Chatwoot Vue 3 frontend into frontend/
Copy the Chatwoot (v4.14.0) frontend runnable subset into frontend/ for
customization:
- app/javascript/ (Vue SPA: dashboard, widget, sdk, portal, superadmin)
- app/views/ (ERB templates for vite-plugin-ruby entrypoint resolution)
- app/helpers/, app/assets/ (Rails view helpers, static assets)
- enterprise/ (Enterprise edition frontend overlay)
- config/vite.json, vite.config.ts, bin/vite (Vite-Rails toolchain)
- package.json, pnpm-lock.yaml, tailwind/postcss/eslint configs
- Gemfile, Gemfile.lock (vite_rails gem for bin/vite binstub)

Excluded Rails backend: controllers, models, services, jobs, mailers,
policies, db, lib, spec, public, node_modules.

Update references to the new frontend location:
- .gitignore: exclude frontend build artifacts (node_modules, tmp, packs),
  keep frontend/bin/ and frontend/vendor/ via negation
- backend/scripts/parity_frontend_smoke.sh: CHATWOOT_DIR default
  reference/chatwoot -> ../frontend
- backend/scripts/parity_frontend_browser_smoke.mjs: same default update
- AGENTS.md: add frontend section with Rails/Vite coupling notes
- README: architecture tree includes frontend/
2026-07-07 14:56:01 +08:00

70 lines
1.6 KiB
JavaScript

// Process [@mention](mention://user/1/Pranav)
const USER_MENTIONS_REGEX = /mention:\/\/(user|team)\/(\d+)\/(.+)/gm;
const buildMentionTokens = () => (state, silent) => {
var label;
var labelEnd;
var labelStart;
var pos;
var res;
var token;
var href = '';
var max = state.posMax;
if (state.src.charCodeAt(state.pos) !== 0x5b /* [ */) {
return false;
}
labelStart = state.pos + 1;
labelEnd = state.md.helpers.parseLinkLabel(state, state.pos, true);
// parser failed to find ']', so it's not a valid link
if (labelEnd < 0) {
return false;
}
label = state.src.slice(labelStart, labelEnd);
pos = labelEnd + 1;
if (pos < max && state.src.charCodeAt(pos) === 0x28 /* ( */) {
pos += 1;
res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax);
if (res.ok) {
href = state.md.normalizeLink(res.str);
if (state.md.validateLink(href)) {
pos = res.pos;
} else {
href = '';
}
}
pos += 1;
}
if (!href.match(new RegExp(USER_MENTIONS_REGEX))) {
return false;
}
if (!silent) {
state.pos = labelStart;
state.posMax = labelEnd;
token = state.push('mention', '');
token.href = href;
token.content = label;
}
state.pos = pos;
state.posMax = max;
return true;
};
const renderMentions = () => (tokens, idx) => {
return `<span class="prosemirror-mention-node">${tokens[idx].content}</span>`;
};
export default function mentionPlugin(md) {
md.renderer.rules.mention = renderMentions(md);
md.inline.ruler.before('link', 'mention', buildMentionTokens(md));
}