thibaud frere commited on
Commit ·
0390c56
1
Parent(s): f9074bc
update doc
Browse filesFiles changed (7)
7 unmodified lines89101112131441 unmodified lines565758596061627 unmodified linesimport rehypeSlug from 'rehype-slug';import rehypeAutolinkHeadings from 'rehype-autolink-headings';import rehypeCitation from 'rehype-citation';import rehypeCodeCopyAndLabel from './plugins/rehype/code-copy-and-label.mjs';import rehypeReferencesAndFootnotes from './plugins/rehype/post-citation.mjs';import remarkIgnoreCitationsInCode from './plugins/remark/ignore-citations-in-code.mjs';import rehypeRestoreAtInCode from './plugins/rehype/restore-at-in-code.mjs';41 unmodified lines}],rehypeReferencesAndFootnotes,rehypeRestoreAtInCode,rehypeCodeCopyAndLabel,rehypeWrapTables]}7 unmodified lines89101112131441 unmodified lines565758596061627 unmodified linesimport rehypeSlug from 'rehype-slug';import rehypeAutolinkHeadings from 'rehype-autolink-headings';import rehypeCitation from 'rehype-citation';import rehypeCodeCopy from './plugins/rehype/code-copy.mjs';import rehypeReferencesAndFootnotes from './plugins/rehype/post-citation.mjs';import remarkIgnoreCitationsInCode from './plugins/remark/ignore-citations-in-code.mjs';import rehypeRestoreAtInCode from './plugins/rehype/restore-at-in-code.mjs';41 unmodified lines}],rehypeReferencesAndFootnotes,rehypeRestoreAtInCode,rehypeCodeCopy,rehypeWrapTables]}
1234567891011121314151617181920212223242526272829303132333435363738394041424344454638 unmodified lines85868788899091929394959697989910026 unmodified lines127128129// Minimal rehype plugin to wrap code blocks with a copy button and a language label// Exported as a standalone module to keep astro.config.mjs leanexport default function rehypeCodeCopyAndLabel() {return (tree) => {// Walk the tree; lightweight visitor to find <pre><code>const visit = (node, parent) => {if (!node || typeof node !== 'object') return;const children = Array.isArray(node.children) ? node.children : [];if (node.tagName === 'pre' && children.some(c => c.tagName === 'code')) {// Find code child and guess languageconst code = children.find(c => c.tagName === 'code');const collectClasses = (val) => Array.isArray(val) ? val.map(String) : (typeof val === 'string' ? String(val).split(/\s+/) : []);const fromClass = (names) => {const hit = names.find((n) => /^language-/.test(String(n)));return hit ? String(hit).replace(/^language-/, '') : '';};const codeClasses = collectClasses(code?.properties?.className);const preClasses = collectClasses(node?.properties?.className);const candidates = [code?.properties?.['data-language'],fromClass(codeClasses),node?.properties?.['data-language'],fromClass(preClasses),];let lang = candidates.find(Boolean) || '';const lower = String(lang).toLowerCase();const toExt = (s) => {switch (String(s).toLowerCase()) {case 'typescript': case 'ts': return 'ts';case 'tsx': return 'tsx';case 'javascript': case 'js': case 'node': return 'js';case 'jsx': return 'jsx';case 'python': case 'py': return 'py';case 'bash': case 'shell': case 'sh': return 'sh';case 'markdown': case 'md': return 'md';case 'yaml': case 'yml': return 'yml';case 'html': return 'html';case 'css': return 'css';case 'json': return 'json';default: return lower || '';}};const ext = toExt(lower);// Determine if single-line block: prefer Shiki lines, then text contentconst countLinesFromShiki = () => {const isLineEl = (el) => el && el.type === 'element' && el.tagName === 'span' && Array.isArray(el.properties?.className) && el.properties.className.includes('line');38 unmodified linesnode.__forceSingle = true;}}// Ensure CSS-only label works: set data-language on <code> and <pre>, and wrappercode.properties = code.properties || {};if (ext) code.properties['data-language'] = ext;node.properties = node.properties || {};if (ext) node.properties['data-language'] = ext;// Replace <pre> with wrapper div.code-card containing button + preconst wrapper = {type: 'element',tagName: 'div',properties: { className: ['code-card'].concat((isSingleLine || node.__forceSingle) ? ['no-copy'] : []), 'data-language': ext },children: (isSingleLine || node.__forceSingle) ? [ node ] : [{type: 'element',26 unmodified lines}123456789101112131438 unmodified lines535455565758596061626326 unmodified lines9091929394// Minimal rehype plugin to wrap code blocks with a copy button// Exported as a standalone module to keep astro.config.mjs leanexport default function rehypeCodeCopy() {return (tree) => {// Walk the tree; lightweight visitor to find <pre><code>const visit = (node, parent) => {if (!node || typeof node !== 'object') return;const children = Array.isArray(node.children) ? node.children : [];if (node.tagName === 'pre' && children.some(c => c.tagName === 'code')) {// Find code childconst code = children.find(c => c.tagName === 'code');// Determine if single-line block: prefer Shiki lines, then text contentconst countLinesFromShiki = () => {const isLineEl = (el) => el && el.type === 'element' && el.tagName === 'span' && Array.isArray(el.properties?.className) && el.properties.className.includes('line');38 unmodified linesnode.__forceSingle = true;}}// Replace <pre> with wrapper div.code-card containing button + preconst wrapper = {type: 'element',tagName: 'div',properties: { className: ['code-card'].concat((isSingleLine || node.__forceSingle) ? ['no-copy'] : []) },children: (isSingleLine || node.__forceSingle) ? [ node ] : [{type: 'element',26 unmodified lines}
12345678---title: "Bringing paper to life:\n A modern template for\n scientific writing"subtitle: "A modern, MDX-first research article template with math, citations and interactive figures."description: "A modern, MDX-first research article template with math, citations and interactive figures."authors:- name: "Thibaud Frere"url: "https://huggingface.co/tfrere"12345678---title: "Bringing paper to life:\n A modern template for\n scientific writing"subtitle: "Ready‑to‑publish workflow so you can focus on ideas rather than infrastructure."description: "Ready‑to‑publish workflow so you can focus on ideas rather than infrastructure."authors:- name: "Thibaud Frere"url: "https://huggingface.co/tfrere"
12345678916 unmodified lines262728293031325 unmodified lines3839404142434445464748495051525354555657585960616263import Sidenote from "../../components/Sidenote.astro";<Sidenote>Welcome to this **single‑page** research article template. It helps you publish **clear**, **modern**, and **interactive** technical writing with **minimal setup**. Grounded in up to date good practices in web dev, it favors interactive explanations, clear notation, and inspectable examples over static snapshots.It offers a **ready‑to‑publish**, **all‑in‑one** workflow so you can focus on **ideas** rather than **infrastructure**.<Fragment slot="aside">Reading time: 20–25 minutes.</Fragment>16 unmodified lines<span className="tag">Dataviz color palettes</span><span className="tag">Optimized images</span><span className="tag">Lightweight bundle</span><span className="tag">SEO-friendly</span><span className="tag">Automatic build</span><span className="tag">Automatic PDF export</span><span className="tag">Dark theme</span>5 unmodified lines</Sidenote>## IntroductionThe web enables what static PDFs can’t: **interactive diagrams**, **progressive notation**, and **exploratory views** that reveal how ideas behave. This template makes **interactive artifacts**—figures, math, code and **inspectable experiments**—first‑class alongside prose, so readers **build intuition** rather than skim results.If you write technical blogs or research notes, you’ll benefit from a **ready‑to‑publish workflow** with clear notation, optimized media, and **automatic builds**.### Who is this forFor people who publish web‑native, interactive writing with minimal setup:- Researchers/engineers with live figures.- Educators crafting explorable explanations.Not a CMS or a multi‑page blog—this is a focused, single‑page, MDX‑first workflow.### Inspired by Distill<Sidenote>This project draws strong inspiration from [**Distill**](https://distill.pub) (2016–2021), which championed clear, web‑native scholarship and set a high standard for interactive scientific communication.To give you a sense of what inspired this template, here is a short, curated list of well‑designed and often interactive works from Distill:- [Growing Neural Cellular Automata](https://distill.pub/2020/growing-ca/)- [Activation Atlas](https://distill.pub/2019/activation-atlas/)1234567891016 unmodified lines272829303132335 unmodified lines3940414243444546474849505152535455565758596061import Sidenote from "../../components/Sidenote.astro";<Sidenote>Welcome to this single‑page **research article template**. It helps you publish **clear**, **modern**, and **interactive technical writing** with **minimal setup**.Grounded in up to date good practices in web dev, it favors **interactive explanations**, **clear notation**, and **inspectable examples** over static snapshots.<Fragment slot="aside">Reading time: 20–25 minutes.</Fragment>16 unmodified lines<span className="tag">Dataviz color palettes</span><span className="tag">Optimized images</span><span className="tag">Lightweight bundle</span><span className="tag">SEO friendly</span><span className="tag">Automatic build</span><span className="tag">Automatic PDF export</span><span className="tag">Dark theme</span>5 unmodified lines</Sidenote>## IntroductionThe web offers what static PDFs can’t: **interactive diagrams**, **progressive notation**, and **exploratory views** that show how ideas behave. This template treats **interactive artifacts**—figures, math, code, and inspectable experiments—as **first‑class** alongside prose, helping readers **build intuition** instead of skimming results.### Who is this forIdeal for anyone creating **web‑native** and **interactive** content with **minimal setup**:- For **scientists** writing modern web‑native papers- For **educators** building explorable lessons.This is not a CMS or a multi‑page blog—it's a **focused**, **single‑page**, **MDX‑first** workflow.### Inspired by Distill<Sidenote>This project draws strong inspiration from [**Distill**](https://distill.pub) (2016–2021), which championed **clear**, **web‑native** scholarship and set a **high standard** for **interactive scientific communication**.To give you a sense of what inspired this template, here is a short, curated list of **well‑designed** and often **interactive** works from Distill:- [Growing Neural Cellular Automata](https://distill.pub/2020/growing-ca/)- [Activation Atlas](https://distill.pub/2019/activation-atlas/)
185 unmodified lines186187188189190191192185 unmodified lines</script><script>// Delegate copy clicks for code blocks injected by rehypeCodeCopyAndLabeldocument.addEventListener('click', async (e) => {const target = e.target instanceof Element ? e.target : null;const btn = target ? target.closest('.code-copy') : null;185 unmodified lines186187188189190191192185 unmodified lines</script><script>// Delegate copy clicks for code blocks injected by rehypeCodeCopydocument.addEventListener('click', async (e) => {const target = e.target instanceof Element ? e.target : null;const btn = target ? target.closest('.code-copy') : null;
173 unmodified lines1741751761771781791801811828 unmodified lines191192193194195196197173 unmodified lines} *//* Fallback if Shiki uses data-lang instead of data-language */.astro-code[data-lang]::after { content: attr(data-lang); }/* Normalize to extensions for common languages */.astro-code[data-language="typescript"]::after { content: "ts"; }.astro-code[data-language="tsx"]::after { content: "tsx"; }.astro-code[data-language="javascript"]::after,8 unmodified lines.astro-code[data-language="yml"]::after { content: "yml"; }.astro-code[data-language="html"]::after { content: "html"; }.astro-code[data-language="css"]::after { content: "css"; }.astro-code[data-language="json"]::after { content: "json"; }/* In Accordions, keep same bottom-right placement */.accordion .astro-code::after { right: 0; bottom: 0; }173 unmodified lines1741751761771781791808 unmodified lines189190191192193194195173 unmodified lines} *//* Fallback if Shiki uses data-lang instead of data-language *//* .astro-code[data-lang]::after { content: attr(data-lang); }.astro-code[data-language="typescript"]::after { content: "ts"; }.astro-code[data-language="tsx"]::after { content: "tsx"; }.astro-code[data-language="javascript"]::after,8 unmodified lines.astro-code[data-language="yml"]::after { content: "yml"; }.astro-code[data-language="html"]::after { content: "html"; }.astro-code[data-language="css"]::after { content: "css"; }.astro-code[data-language="json"]::after { content: "json"; } *//* In Accordions, keep same bottom-right placement */.accordion .astro-code::after { right: 0; bottom: 0; }
3 unmodified lines456789101112133 unmodified linesdisplay: inline-flex;align-items: center;gap: 6px;padding: 10px 16px;font-size: 12px;line-height: 1;border-radius: 100px;background: var(--surface-bg);border: 1px solid var(--border-color);color: var(--text-color);3 unmodified lines456789101112133 unmodified linesdisplay: inline-flex;align-items: center;gap: 6px;padding: 8px 12px;font-size: 12px;line-height: 1;border-radius: var(--button-radius);background: var(--surface-bg);border: 1px solid var(--border-color);color: var(--text-color);
app/astro.config.mjs+2-2
app/plugins/rehype/code-copy-and-label.mjs → app/plugins/rehype/code-copy.mjsRenamed+6-41
app/src/content/article.mdx+2-2
app/src/content/chapters/introduction.mdx+11-13
app/src/pages/index.astro+1-1
app/src/styles/components/_code.css+2-4
app/src/styles/components/_tag.css+2-2