Download published/default/index.html from tfrere/collab-editor-data: direct link, hf CLI and curl.
- Browser
- Download file 45.9 kB
-
https://huggingface.co/datasets/tfrere/collab-editor-data/resolve/main/published/default/index.html
- Command line
-
hf download hf://datasets/tfrere/collab-editor-data/published/default/index.html
-
curl -L -o index.html https://huggingface.co/datasets/tfrere/collab-editor-data/resolve/main/published/default/index.html
45.9 kB
| <html lang="en" data-theme="dark"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Scaling Laws for Neural Language Models</title> | |
| <meta name="description" content="An empirical study of scaling behavior across model size, data, and compute budgets."> | |
| <meta name="author" content="Alice Martin, Bob Chen, Carol Wu"> | |
| <!-- Open Graph --> | |
| <meta property="og:type" content="article"> | |
| <meta property="og:title" content="Scaling Laws for Neural Language Models"> | |
| <meta property="og:description" content="An empirical study of scaling behavior across model size, data, and compute budgets."> | |
| <meta property="article:published_time" content="Apr. 13, 2026"> | |
| <meta property="article:author" content="Alice Martin"> | |
| <meta property="article:author" content="Bob Chen"> | |
| <meta property="article:author" content="Carol Wu"> | |
| <!-- Twitter Card --> | |
| <meta name="twitter:card" content="summary_large_image"> | |
| <meta name="twitter:title" content="Scaling Laws for Neural Language Models"> | |
| <meta name="twitter:description" content="An empirical study of scaling behavior across model size, data, and compute budgets."> | |
| <!-- KaTeX CSS --> | |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css" | |
| integrity="sha384-zh0CIslj3dQfMxK3pZnPJAb3bprHitCE2vBz9TyOTICAn3fso5GYa90qPNMBclov" | |
| crossorigin="anonymous"> | |
| <!-- highlight.js theme --> | |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/styles/github-dark.min.css"> | |
| <style> | |
| /* ----------------------------------------------------------------------- | |
| Design tokens - Light / Dark theming | |
| Usage: var(--token-name) | |
| Toggle: data-theme="light" or data-theme="dark" on <html> | |
| Default: follows prefers-color-scheme | |
| ----------------------------------------------------------------------- */ | |
| :root, | |
| [data-theme="light"] { | |
| --text-primary: #1a1a1a; | |
| --text-secondary: #555; | |
| --text-tertiary: #888; | |
| --text-faint: #aaa; | |
| --text-heading: #111; | |
| --text-heading-secondary: #222; | |
| --text-strong: #000; | |
| --bg-primary: #ffffff; | |
| --bg-secondary: #f7f7f7; | |
| --bg-tertiary: #f0f0f0; | |
| --bg-hover: rgba(0, 0, 0, 0.03); | |
| --bg-overlay: rgba(0, 0, 0, 0.5); | |
| --bg-tooltip: #ffffff; | |
| --bg-surface: #ffffff; | |
| --bg-code: rgba(0, 0, 0, 0.04); | |
| --bg-code-block: #fafafa; | |
| --border: #e0e0e0; | |
| --border-light: #eeeeee; | |
| --border-focus: rgba(124, 58, 237, 0.5); | |
| --accent: #7c3aed; | |
| --accent-light: #958DF1; | |
| --accent-bg: rgba(124, 58, 237, 0.08); | |
| --accent-bg-hover: rgba(124, 58, 237, 0.15); | |
| --accent-text: #6d28d9; | |
| --code-text: #d63384; | |
| --code-comment: #6a737d; | |
| --code-keyword: #8250df; | |
| --code-string: #0a6640; | |
| --code-number: #b35900; | |
| --code-variable: #d63384; | |
| --code-type: #b35900; | |
| --code-function: #0550ae; | |
| --code-tag: #d63384; | |
| --code-attr: #b35900; | |
| --code-symbol: #0a6640; | |
| --code-meta: #0550ae; | |
| --code-deletion: #d63384; | |
| --danger: #dc2626; | |
| --danger-bg: rgba(220, 38, 38, 0.08); | |
| --danger-bg-hover: rgba(220, 38, 38, 0.15); | |
| --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08); | |
| --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1); | |
| --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12); | |
| --katex-color: #1a1a1a; | |
| } | |
| [data-theme="dark"] { | |
| --text-primary: rgba(255, 255, 255, 0.85); | |
| --text-secondary: rgba(255, 255, 255, 0.5); | |
| --text-tertiary: rgba(255, 255, 255, 0.4); | |
| --text-faint: rgba(255, 255, 255, 0.25); | |
| --text-heading: #fff; | |
| --text-heading-secondary: rgba(255, 255, 255, 0.9); | |
| --text-strong: rgba(255, 255, 255, 0.95); | |
| --bg-primary: #0a0a0a; | |
| --bg-secondary: #1a1a1a; | |
| --bg-tertiary: #1e1e1e; | |
| --bg-hover: rgba(255, 255, 255, 0.03); | |
| --bg-overlay: rgba(0, 0, 0, 0.5); | |
| --bg-tooltip: #1e1e2e; | |
| --bg-surface: #1a1a1a; | |
| --bg-code: rgba(255, 255, 255, 0.06); | |
| --bg-code-block: rgba(255, 255, 255, 0.03); | |
| --border: rgba(255, 255, 255, 0.1); | |
| --border-light: rgba(255, 255, 255, 0.06); | |
| --border-focus: rgba(149, 141, 241, 0.5); | |
| --accent: #7c3aed; | |
| --accent-light: #958DF1; | |
| --accent-bg: rgba(149, 141, 241, 0.15); | |
| --accent-bg-hover: rgba(149, 141, 241, 0.25); | |
| --accent-text: #b4aef7; | |
| --code-text: #e06c75; | |
| --code-comment: #5c6370; | |
| --code-keyword: #c678dd; | |
| --code-string: #98c379; | |
| --code-number: #d19a66; | |
| --code-variable: #e06c75; | |
| --code-type: #e5c07b; | |
| --code-function: #61afef; | |
| --code-tag: #e06c75; | |
| --code-attr: #d19a66; | |
| --code-symbol: #56b6c2; | |
| --code-meta: #61afef; | |
| --code-deletion: #e06c75; | |
| --danger: #e06c75; | |
| --danger-bg: rgba(224, 108, 117, 0.12); | |
| --danger-bg-hover: rgba(224, 108, 117, 0.25); | |
| --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3); | |
| --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4); | |
| --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5); | |
| --katex-color: rgba(255, 255, 255, 0.85); | |
| } | |
| @media (prefers-color-scheme: dark) { | |
| :root:not([data-theme="light"]) { | |
| --text-primary: rgba(255, 255, 255, 0.85); | |
| --text-secondary: rgba(255, 255, 255, 0.5); | |
| --text-tertiary: rgba(255, 255, 255, 0.4); | |
| --text-faint: rgba(255, 255, 255, 0.25); | |
| --text-heading: #fff; | |
| --text-heading-secondary: rgba(255, 255, 255, 0.9); | |
| --text-strong: rgba(255, 255, 255, 0.95); | |
| --bg-primary: #0a0a0a; | |
| --bg-secondary: #1a1a1a; | |
| --bg-tertiary: #1e1e1e; | |
| --bg-hover: rgba(255, 255, 255, 0.03); | |
| --bg-overlay: rgba(0, 0, 0, 0.5); | |
| --bg-tooltip: #1e1e2e; | |
| --bg-surface: #1a1a1a; | |
| --bg-code: rgba(255, 255, 255, 0.06); | |
| --bg-code-block: rgba(255, 255, 255, 0.03); | |
| --border: rgba(255, 255, 255, 0.1); | |
| --border-light: rgba(255, 255, 255, 0.06); | |
| --border-focus: rgba(149, 141, 241, 0.5); | |
| --accent: #7c3aed; | |
| --accent-light: #958DF1; | |
| --accent-bg: rgba(149, 141, 241, 0.15); | |
| --accent-bg-hover: rgba(149, 141, 241, 0.25); | |
| --accent-text: #b4aef7; | |
| --code-text: #e06c75; | |
| --code-comment: #5c6370; | |
| --code-keyword: #c678dd; | |
| --code-string: #98c379; | |
| --code-number: #d19a66; | |
| --code-variable: #e06c75; | |
| --code-type: #e5c07b; | |
| --code-function: #61afef; | |
| --code-tag: #e06c75; | |
| --code-attr: #d19a66; | |
| --code-symbol: #56b6c2; | |
| --code-meta: #61afef; | |
| --code-deletion: #e06c75; | |
| --danger: #e06c75; | |
| --danger-bg: rgba(224, 108, 117, 0.12); | |
| --danger-bg-hover: rgba(224, 108, 117, 0.25); | |
| --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3); | |
| --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4); | |
| --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5); | |
| --katex-color: rgba(255, 255, 255, 0.85); | |
| } | |
| } | |
| /* ----------------------------------------------------------------------- | |
| Article content styles | |
| Shared between editor and published version. | |
| Uses CSS variables from tokens.css for light/dark theming. | |
| ----------------------------------------------------------------------- */ | |
| /* Base typography */ | |
| .tiptap { | |
| outline: none; | |
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; | |
| font-size: 1rem; | |
| line-height: 1.7; | |
| color: var(--text-primary); | |
| max-width: 780px; | |
| margin-left: auto; | |
| margin-right: auto; | |
| padding: 0 32px 0 64px; | |
| min-height: 100%; | |
| overflow-wrap: break-word; | |
| word-break: break-word; | |
| } | |
| .tiptap > *:first-child { | |
| margin-top: 0; | |
| } | |
| /* Headings */ | |
| .tiptap h1 { | |
| font-size: 2rem; | |
| font-weight: 700; | |
| color: var(--text-heading); | |
| line-height: 1.2; | |
| margin: 2em 0 0.4em; | |
| letter-spacing: -0.02em; | |
| } | |
| .tiptap h1:first-child { | |
| margin-top: 0; | |
| } | |
| .tiptap h2 { | |
| font-size: 1.5rem; | |
| font-weight: 600; | |
| color: var(--text-heading-secondary); | |
| line-height: 1.3; | |
| margin: 1.8em 0 0.4em; | |
| letter-spacing: -0.01em; | |
| } | |
| .tiptap h3 { | |
| font-size: 1.2rem; | |
| font-weight: 600; | |
| color: var(--text-primary); | |
| line-height: 1.4; | |
| margin: 1.5em 0 0.3em; | |
| } | |
| /* Paragraphs */ | |
| .tiptap p { | |
| margin: 0.5em 0; | |
| } | |
| /* Lists */ | |
| .tiptap ul, | |
| .tiptap ol { | |
| padding-left: 1.5rem; | |
| margin: 0.5em 0; | |
| } | |
| .tiptap li { | |
| margin: 0.25em 0; | |
| } | |
| .tiptap li p { | |
| margin: 0.15em 0; | |
| } | |
| /* Blockquote */ | |
| .tiptap blockquote { | |
| border-left: 3px solid var(--border); | |
| padding-left: 1rem; | |
| margin: 1em 0; | |
| color: var(--text-secondary); | |
| } | |
| .tiptap blockquote p { | |
| margin: 0.4em 0; | |
| } | |
| /* Inline code */ | |
| .tiptap code { | |
| font-family: "SFMono-Regular", "Fira Code", "Fira Mono", Menlo, Consolas, monospace; | |
| background: var(--bg-code); | |
| padding: 0.15em 0.4em; | |
| border-radius: 4px; | |
| font-size: 0.88em; | |
| color: var(--code-text); | |
| } | |
| /* Code block */ | |
| .tiptap pre { | |
| background: var(--bg-code-block); | |
| border: 1px solid var(--border-light); | |
| border-radius: 8px; | |
| padding: 1rem 1.25rem; | |
| margin: 1em 0; | |
| overflow-x: auto; | |
| } | |
| .tiptap pre code { | |
| background: none; | |
| padding: 0; | |
| color: var(--text-secondary); | |
| font-size: 0.875rem; | |
| line-height: 1.6; | |
| } | |
| /* Syntax highlighting */ | |
| .tiptap pre code .hljs-comment, | |
| .tiptap pre code .hljs-quote { | |
| color: var(--code-comment); | |
| font-style: italic; | |
| } | |
| .tiptap pre code .hljs-keyword, | |
| .tiptap pre code .hljs-selector-tag, | |
| .tiptap pre code .hljs-addition { | |
| color: var(--code-keyword); | |
| } | |
| .tiptap pre code .hljs-string, | |
| .tiptap pre code .hljs-meta .hljs-string, | |
| .tiptap pre code .hljs-regexp, | |
| .tiptap pre code .hljs-doctag { | |
| color: var(--code-string); | |
| } | |
| .tiptap pre code .hljs-number, | |
| .tiptap pre code .hljs-literal, | |
| .tiptap pre code .hljs-bullet { | |
| color: var(--code-number); | |
| } | |
| .tiptap pre code .hljs-variable, | |
| .tiptap pre code .hljs-template-variable, | |
| .tiptap pre code .hljs-tag .hljs-attr { | |
| color: var(--code-variable); | |
| } | |
| .tiptap pre code .hljs-type, | |
| .tiptap pre code .hljs-built_in, | |
| .tiptap pre code .hljs-class .hljs-title, | |
| .tiptap pre code .hljs-title.class_ { | |
| color: var(--code-type); | |
| } | |
| .tiptap pre code .hljs-function, | |
| .tiptap pre code .hljs-title, | |
| .tiptap pre code .hljs-section { | |
| color: var(--code-function); | |
| } | |
| .tiptap pre code .hljs-name, | |
| .tiptap pre code .hljs-tag { | |
| color: var(--code-tag); | |
| } | |
| .tiptap pre code .hljs-attr { | |
| color: var(--code-attr); | |
| } | |
| .tiptap pre code .hljs-symbol, | |
| .tiptap pre code .hljs-link { | |
| color: var(--code-symbol); | |
| } | |
| .tiptap pre code .hljs-meta, | |
| .tiptap pre code .hljs-selector-id, | |
| .tiptap pre code .hljs-selector-class { | |
| color: var(--code-meta); | |
| } | |
| .tiptap pre code .hljs-deletion { | |
| color: var(--code-deletion); | |
| } | |
| .tiptap pre code .hljs-emphasis { | |
| font-style: italic; | |
| } | |
| .tiptap pre code .hljs-strong { | |
| font-weight: 700; | |
| } | |
| /* Horizontal rule */ | |
| .tiptap hr { | |
| border: none; | |
| border-top: 1px solid var(--border); | |
| margin: 2em 0; | |
| } | |
| /* Tables */ | |
| .tiptap table { | |
| border-collapse: collapse; | |
| width: 100%; | |
| margin: 1em 0; | |
| overflow: hidden; | |
| border-radius: 6px; | |
| border: 1px solid var(--border-light); | |
| } | |
| .tiptap th, | |
| .tiptap td { | |
| padding: 0.5rem 0.75rem; | |
| border: 1px solid var(--border-light); | |
| text-align: left; | |
| font-size: 0.875rem; | |
| min-width: 80px; | |
| } | |
| .tiptap th { | |
| background: var(--bg-code); | |
| color: var(--text-secondary); | |
| font-weight: 600; | |
| font-size: 0.8125rem; | |
| text-transform: uppercase; | |
| letter-spacing: 0.03em; | |
| } | |
| .tiptap td { | |
| color: var(--text-primary); | |
| } | |
| .tiptap tr:hover td { | |
| background: var(--bg-hover); | |
| } | |
| /* Links */ | |
| .tiptap a, | |
| .tiptap .editor-link { | |
| color: var(--accent-light); | |
| text-decoration: underline; | |
| text-decoration-color: rgba(149, 141, 241, 0.4); | |
| text-underline-offset: 2px; | |
| transition: text-decoration-color 0.15s; | |
| } | |
| .tiptap a:hover, | |
| .tiptap .editor-link:hover { | |
| text-decoration-color: rgba(149, 141, 241, 0.8); | |
| } | |
| /* Bold */ | |
| .tiptap strong { | |
| font-weight: 600; | |
| color: var(--text-strong); | |
| } | |
| /* Images */ | |
| .tiptap img { | |
| max-width: 100%; | |
| height: auto; | |
| border-radius: 8px; | |
| margin: 1em 0; | |
| } | |
| /* Math - inline */ | |
| .tiptap [data-type="inline-math"] .tiptap-mathematics-render { | |
| padding: 0 0.2em; | |
| border-radius: 3px; | |
| transition: background 0.15s; | |
| } | |
| .tiptap [data-type="inline-math"] .tiptap-mathematics-render:hover { | |
| background: var(--bg-code); | |
| } | |
| /* Math - block */ | |
| .tiptap [data-type="block-math"] { | |
| margin: 1em 0; | |
| } | |
| .tiptap [data-type="block-math"] .tiptap-mathematics-render { | |
| display: flex; | |
| justify-content: center; | |
| padding: 1rem 0; | |
| border-radius: 8px; | |
| transition: background 0.15s; | |
| } | |
| .tiptap [data-type="block-math"] .tiptap-mathematics-render:hover { | |
| background: var(--bg-hover); | |
| } | |
| /* KaTeX color */ | |
| .tiptap .katex { | |
| color: var(--katex-color); | |
| } | |
| /* Citation inline node */ | |
| .citation-node { | |
| position: relative; | |
| color: var(--accent-light); | |
| cursor: default; | |
| font-size: 0.9em; | |
| white-space: nowrap; | |
| text-decoration: underline; | |
| text-decoration-color: rgba(149, 141, 241, 0.3); | |
| text-underline-offset: 2px; | |
| transition: text-decoration-color 0.15s; | |
| } | |
| .citation-node:hover { | |
| text-decoration-color: rgba(149, 141, 241, 0.7); | |
| } | |
| /* Citation hover tooltip */ | |
| .citation-tooltip { | |
| position: absolute; | |
| bottom: calc(100% + 8px); | |
| left: 50%; | |
| transform: translateX(-50%); | |
| background: var(--bg-tooltip); | |
| border: 1px solid var(--border); | |
| border-radius: 8px; | |
| padding: 0.75rem; | |
| min-width: 240px; | |
| max-width: 320px; | |
| box-shadow: var(--shadow-lg); | |
| z-index: 100; | |
| white-space: normal; | |
| pointer-events: auto; | |
| } | |
| .citation-tooltip-title { | |
| color: var(--text-heading-secondary); | |
| font-size: 0.8125rem; | |
| font-weight: 500; | |
| line-height: 1.4; | |
| margin-bottom: 0.35rem; | |
| } | |
| .citation-tooltip-journal { | |
| color: var(--text-secondary); | |
| font-size: 0.75rem; | |
| font-style: italic; | |
| line-height: 1.3; | |
| } | |
| .citation-tooltip-doi { | |
| color: var(--text-tertiary); | |
| font-size: 0.7rem; | |
| font-family: "SFMono-Regular", "Fira Code", monospace; | |
| margin-top: 0.35rem; | |
| overflow: hidden; | |
| text-overflow: ellipsis; | |
| } | |
| .citation-tooltip-remove { | |
| display: block; | |
| margin-top: 0.5rem; | |
| margin-left: auto; | |
| padding: 0.25rem 0.6rem; | |
| border: none; | |
| border-radius: 4px; | |
| background: var(--danger-bg); | |
| color: var(--danger); | |
| font-size: 0.7rem; | |
| font-family: inherit; | |
| cursor: pointer; | |
| transition: background 0.15s; | |
| } | |
| .citation-tooltip-remove:hover { | |
| background: var(--danger-bg-hover); | |
| } | |
| /* Bibliography block */ | |
| .bibliography-block { | |
| margin: 2em 0 1em; | |
| padding-top: 1.5em; | |
| border-top: 1px solid var(--border); | |
| } | |
| .bibliography-title { | |
| font-size: 1.3rem; | |
| font-weight: 600; | |
| color: var(--text-heading-secondary); | |
| margin: 0 0 1em; | |
| } | |
| .bibliography-empty { | |
| color: var(--text-faint); | |
| font-size: 0.875rem; | |
| font-style: italic; | |
| } | |
| .bibliography-content { | |
| font-size: 0.875rem; | |
| line-height: 1.7; | |
| color: var(--text-secondary); | |
| } | |
| .bibliography-content .csl-entry { | |
| margin-bottom: 0.75em; | |
| padding-left: 2em; | |
| text-indent: -2em; | |
| } | |
| .bibliography-content .csl-entry i { | |
| font-style: italic; | |
| } | |
| /* Custom component blocks */ | |
| .component-content > *:first-child { | |
| margin-top: 0; | |
| } | |
| .component-content > *:last-child { | |
| margin-bottom: 0; | |
| } | |
| /* Glossary inline node */ | |
| .glossary-node { | |
| position: relative; | |
| display: inline; | |
| border-bottom: 1px dashed rgba(149, 141, 241, 0.5); | |
| color: rgba(149, 141, 241, 0.9); | |
| cursor: help; | |
| } | |
| .glossary-tooltip { | |
| position: absolute; | |
| bottom: calc(100% + 6px); | |
| left: 50%; | |
| transform: translateX(-50%); | |
| background: var(--bg-tooltip); | |
| border: 1px solid var(--border); | |
| border-radius: 8px; | |
| padding: 10px 14px; | |
| min-width: 200px; | |
| max-width: 320px; | |
| z-index: 50; | |
| box-shadow: var(--shadow-lg); | |
| } | |
| .glossary-tooltip-term { | |
| font-weight: 700; | |
| font-size: 13px; | |
| color: var(--text-heading-secondary); | |
| margin-bottom: 4px; | |
| } | |
| .glossary-tooltip-def { | |
| font-size: 12px; | |
| color: var(--text-secondary); | |
| line-height: 1.5; | |
| } | |
| .glossary-tooltip-remove { | |
| margin-top: 8px; | |
| background: none; | |
| border: none; | |
| color: var(--danger); | |
| font-size: 11px; | |
| cursor: pointer; | |
| padding: 0; | |
| opacity: 0.8; | |
| } | |
| .glossary-tooltip-remove:hover { | |
| opacity: 1; | |
| } | |
| /* Footnote inline node */ | |
| .footnote-node { | |
| position: relative; | |
| display: inline; | |
| } | |
| .footnote-marker { | |
| color: rgba(149, 141, 241, 0.9); | |
| cursor: pointer; | |
| font-size: 0.75em; | |
| font-weight: 700; | |
| margin: 0 1px; | |
| } | |
| .footnote-tooltip { | |
| position: absolute; | |
| bottom: calc(100% + 6px); | |
| left: 50%; | |
| transform: translateX(-50%); | |
| background: var(--bg-tooltip); | |
| border: 1px solid var(--border); | |
| border-radius: 8px; | |
| padding: 10px 14px; | |
| min-width: 220px; | |
| max-width: 360px; | |
| z-index: 50; | |
| box-shadow: var(--shadow-lg); | |
| } | |
| .footnote-tooltip-content { | |
| font-size: 12px; | |
| color: var(--text-secondary); | |
| line-height: 1.5; | |
| } | |
| /* Stack columns */ | |
| .stack-columns { | |
| display: contents; | |
| } | |
| .stack-columns > div[data-type="stack-column"] { | |
| border: 1px dashed var(--border-light); | |
| border-radius: 6px; | |
| padding: 8px; | |
| min-height: 40px; | |
| } | |
| .stack-columns > div[data-type="stack-column"] > *:first-child { | |
| margin-top: 0; | |
| } | |
| .stack-columns > div[data-type="stack-column"] > *:last-child { | |
| margin-bottom: 0; | |
| } | |
| /* Published article layout */ | |
| body { | |
| margin: 0; | |
| padding: 0; | |
| background: var(--bg-primary); | |
| color: var(--text-primary); | |
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; | |
| } | |
| /* Grid: TOC | Article | (empty right) */ | |
| .content-grid { | |
| max-width: 1280px; | |
| margin: 0 auto; | |
| padding: 0 24px; | |
| margin-top: 40px; | |
| display: grid; | |
| grid-template-columns: 260px minmax(0, 680px) 260px; | |
| gap: 32px; | |
| align-items: start; | |
| } | |
| .article-header { | |
| margin-bottom: 2rem; | |
| padding-bottom: 1.5rem; | |
| border-bottom: 1px solid var(--border); | |
| } | |
| .article-header h1 { | |
| font-size: 2.5rem; | |
| font-weight: 700; | |
| color: var(--text-heading); | |
| line-height: 1.2; | |
| margin: 0 0 0.5rem; | |
| letter-spacing: -0.02em; | |
| } | |
| .article-header .authors { | |
| color: var(--text-secondary); | |
| font-size: 0.9375rem; | |
| margin-bottom: 0.25rem; | |
| line-height: 1.6; | |
| } | |
| .article-header .author-link { | |
| color: var(--accent-light); | |
| text-decoration: none; | |
| } | |
| .article-header .author-link:hover { | |
| text-decoration: underline; | |
| } | |
| .article-header .author-affiliation { | |
| color: var(--text-tertiary); | |
| font-size: 0.8125rem; | |
| margin-left: 0.25rem; | |
| } | |
| .article-header .author-affiliation::before { content: "("; } | |
| .article-header .author-affiliation::after { content: ")"; } | |
| .article-header .date { | |
| color: var(--text-tertiary); | |
| font-size: 0.8125rem; | |
| } | |
| /* Theme toggle */ | |
| .theme-toggle { | |
| position: fixed; | |
| top: 1rem; | |
| right: 1rem; | |
| background: var(--bg-secondary); | |
| border: 1px solid var(--border); | |
| border-radius: 8px; | |
| padding: 0.5rem; | |
| cursor: pointer; | |
| font-size: 1.2rem; | |
| line-height: 1; | |
| z-index: 100; | |
| } | |
| /* ---------- Table of Contents (desktop sticky) ---------- */ | |
| .table-of-contents { | |
| position: sticky; | |
| top: 32px; | |
| margin-top: 12px; | |
| } | |
| .table-of-contents .title { | |
| font-weight: 600; | |
| font-size: 14px; | |
| margin-bottom: 8px; | |
| color: var(--text-primary); | |
| } | |
| .table-of-contents nav { | |
| border-left: 1px solid var(--border); | |
| padding-left: 16px; | |
| font-size: 13px; | |
| } | |
| .table-of-contents nav ul { | |
| margin: 0 0 6px; | |
| padding-left: 1em; | |
| } | |
| .table-of-contents nav li { | |
| list-style: none; | |
| margin: 0.25em 0; | |
| } | |
| .table-of-contents nav a, | |
| .table-of-contents nav a:link, | |
| .table-of-contents nav a:visited { | |
| color: var(--text-primary); | |
| text-decoration: none; | |
| border-bottom: none; | |
| } | |
| .table-of-contents nav > ul > li > a { | |
| font-weight: 700; | |
| } | |
| .table-of-contents nav a:hover { | |
| text-decoration: underline solid var(--text-tertiary); | |
| } | |
| .table-of-contents nav a.active { | |
| text-decoration: underline; | |
| } | |
| /* Collapsible sub-sections */ | |
| .table-of-contents nav.toc-collapsible li > ul, | |
| .toc-mobile-sidebar nav.toc-collapsible li > ul { | |
| overflow: hidden; | |
| transition: height 200ms ease; | |
| } | |
| /* ---------- Mobile TOC toggle ---------- */ | |
| .toc-mobile-toggle { | |
| display: none; | |
| position: fixed; | |
| top: 1rem; | |
| left: 1rem; | |
| z-index: 200; | |
| width: 40px; | |
| height: 40px; | |
| border-radius: 50%; | |
| border: 1px solid var(--border); | |
| background: var(--bg-primary); | |
| color: var(--text-primary); | |
| cursor: pointer; | |
| align-items: center; | |
| justify-content: center; | |
| box-shadow: 0 2px 12px rgba(0,0,0,.08); | |
| transition: transform 150ms ease, box-shadow 150ms ease; | |
| } | |
| .toc-mobile-toggle:active { transform: scale(0.92); } | |
| /* ---------- Mobile backdrop ---------- */ | |
| .toc-mobile-backdrop { | |
| display: none; | |
| position: fixed; | |
| inset: 0; | |
| z-index: 201; | |
| background: rgba(0,0,0,.4); | |
| opacity: 0; | |
| pointer-events: none; | |
| transition: opacity 250ms ease; | |
| } | |
| .toc-mobile-backdrop.open { opacity: 1; pointer-events: auto; } | |
| /* ---------- Mobile sidebar ---------- */ | |
| .toc-mobile-sidebar { | |
| display: none; | |
| position: fixed; | |
| top: 0; left: 0; bottom: 0; | |
| z-index: 202; | |
| width: min(320px, 85vw); | |
| background: var(--bg-primary); | |
| border-right: 1px solid var(--border); | |
| transform: translateX(-100%); | |
| transition: transform 300ms cubic-bezier(.4,0,.2,1); | |
| flex-direction: column; | |
| } | |
| .toc-mobile-sidebar.open { transform: translateX(0); } | |
| .toc-mobile-sidebar__header { | |
| display: flex; | |
| align-items: center; | |
| justify-content: space-between; | |
| padding: 0.75rem 1rem; | |
| border-bottom: 1px solid var(--border); | |
| flex-shrink: 0; | |
| } | |
| .toc-mobile-sidebar__title { font-weight: 700; font-size: 15px; color: var(--text-primary); } | |
| .toc-mobile-sidebar__close { | |
| background: none; border: none; color: var(--text-tertiary); | |
| cursor: pointer; padding: 6px; border-radius: 6px; | |
| display: flex; align-items: center; justify-content: center; | |
| transition: color 150ms ease, background 150ms ease; | |
| } | |
| .toc-mobile-sidebar__close:hover { color: var(--text-primary); background: var(--bg-secondary); } | |
| .toc-mobile-sidebar__body { | |
| flex: 1; | |
| overflow-y: auto; | |
| -webkit-overflow-scrolling: touch; | |
| padding: 0.75rem 1rem 1.5rem; | |
| } | |
| .toc-mobile-sidebar nav ul { margin: 0 0 6px; padding-left: 1em; } | |
| .toc-mobile-sidebar nav li { list-style: none; margin: 0.35em 0; } | |
| .toc-mobile-sidebar nav a, | |
| .toc-mobile-sidebar nav a:link, | |
| .toc-mobile-sidebar nav a:visited { | |
| color: var(--text-primary); | |
| text-decoration: none; | |
| border-bottom: none; | |
| font-size: 14px; | |
| line-height: 1.5; | |
| } | |
| .toc-mobile-sidebar nav > ul > li > a { font-weight: 700; } | |
| .toc-mobile-sidebar nav a:hover { text-decoration: underline solid var(--text-tertiary); } | |
| .toc-mobile-sidebar nav a.active { color: var(--accent-light); text-decoration: underline; } | |
| /* ---------- Responsive: collapse below 1100px ---------- */ | |
| @media (max-width: 1100px) { | |
| .content-grid { | |
| overflow: hidden; | |
| display: block; | |
| padding: 0 16px; | |
| margin-top: 0.5rem; | |
| } | |
| .table-of-contents { position: static; display: none; } | |
| .toc-mobile-toggle { display: flex; } | |
| .toc-mobile-backdrop { display: block; } | |
| .toc-mobile-sidebar { display: flex; } | |
| } | |
| /* Accordion as details/summary */ | |
| details[data-component="accordion"] { | |
| border: 1px solid var(--border); | |
| border-radius: 8px; | |
| padding: 0; | |
| margin: 1em 0; | |
| } | |
| details[data-component="accordion"] > summary { | |
| padding: 0.75rem 1rem; | |
| cursor: pointer; | |
| font-weight: 600; | |
| color: var(--text-heading-secondary); | |
| list-style: none; | |
| user-select: none; | |
| } | |
| details[data-component="accordion"] > summary::-webkit-details-marker { display: none; } | |
| details[data-component="accordion"] > summary::before { | |
| content: "\25B8"; | |
| display: inline-block; | |
| margin-right: 0.5rem; | |
| transition: transform 0.2s; | |
| } | |
| details[data-component="accordion"][open] > summary::before { transform: rotate(90deg); } | |
| details[data-component="accordion"] > .accordion-content { padding: 0 1rem 1rem; } | |
| /* Image lightbox dialog */ | |
| dialog.lightbox { border: none; background: transparent; padding: 0; max-width: 95vw; max-height: 95vh; } | |
| dialog.lightbox::backdrop { background: rgba(0, 0, 0, 0.85); } | |
| dialog.lightbox img { max-width: 95vw; max-height: 90vh; object-fit: contain; border-radius: 4px; } | |
| /* Print */ | |
| @media print { | |
| .table-of-contents, .toc-mobile-toggle, .toc-mobile-backdrop, .toc-mobile-sidebar, .theme-toggle { display: none ; } | |
| .content-grid { display: block ; } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <button class="theme-toggle" aria-label="Toggle theme" onclick="toggleTheme()">🌓</button> | |
| <!-- Mobile TOC toggle --> | |
| <button class="toc-mobile-toggle" aria-label="Open table of contents" aria-expanded="false"> | |
| <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> | |
| <line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/> | |
| </svg> | |
| </button> | |
| <div class="toc-mobile-backdrop" aria-hidden="true"></div> | |
| <aside class="toc-mobile-sidebar" aria-label="Table of Contents"> | |
| <div class="toc-mobile-sidebar__header"> | |
| <span class="toc-mobile-sidebar__title">Table of Contents</span> | |
| <button class="toc-mobile-sidebar__close" aria-label="Close"> | |
| <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> | |
| <line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/> | |
| </svg> | |
| </button> | |
| </div> | |
| <div class="toc-mobile-sidebar__body" id="toc-mobile-placeholder"></div> | |
| </aside> | |
| <section class="content-grid"> | |
| <nav class="table-of-contents" aria-label="Table of Contents"> | |
| <div class="title">Table of Contents</div> | |
| <div id="toc-placeholder"></div> | |
| </nav> | |
| <article> | |
| <header class="article-header"> | |
| <h1>Scaling Laws for Neural Language Models</h1> | |
| <div class="authors"><span class="author"><a href="https://example.com/alice" class="author-link" target="_blank" rel="noopener">Alice Martin</a><span class="author-affiliation">Hugging Face</span></span><span class="author-sep">, </span><span class="author"><span class="author-name">Bob Chen</span><span class="author-affiliation">Hugging Face, MIT</span></span><span class="author-sep">, </span><span class="author"><span class="author-name">Carol Wu</span><span class="author-affiliation">MIT</span></span></div> | |
| <p class="date">April 13, 2026</p> | |
| </header> | |
| <div class="tiptap"> | |
| <h1>Welcome to the Collaborative Editor</h1><p>This demo article showcases <strong>every content type</strong> available in the editor. Feel free to edit, delete, or rewrite anything — the AI assistant in the left panel can help you.</p><h2>Text formatting</h2><p>You can make text <strong>bold</strong>, <em>italic</em>, or <s>strikethrough</s>. Combine them for <strong><em>bold italic</em></strong>. Use <code>inline code</code> for technical terms, and add <a target="_blank" rel="noopener noreferrer nofollow" class="editor-link" href="https://huggingface.co">links</a> to external resources.</p><h2>Lists</h2><h3>Unordered list</h3><ul><li><p>First item with some context</p></li><li><p>Second item — supports <strong>rich formatting</strong> inside</p></li><li><p>Third item with <code>inline code</code></p></li></ul><h3>Ordered list</h3><ol><li><p>Prepare the dataset</p></li><li><p>Fine-tune the model</p></li><li><p>Evaluate on the test split</p></li><li><p>Deploy to production</p></li></ol><h2>Blockquote</h2><blockquote><p>"The best way to predict the future is to invent it." — Alan Kay</p></blockquote><h2>Code block</h2><pre><code class="language-python">import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| model_id = "meta-llama/Llama-3-8B" | |
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_id, | |
| torch_dtype=torch.bfloat16, | |
| device_map="auto", | |
| ) | |
| prompt = "The future of AI is" | |
| inputs = tokenizer(prompt, return_tensors="pt").to(model.device) | |
| outputs = model.generate(**inputs, max_new_tokens=100) | |
| print(tokenizer.decode(outputs[0], skip_special_tokens=True))</code></pre><h2>Table</h2><table style="min-width: 100px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p>Model</p></th><th colspan="1" rowspan="1"><p>Parameters</p></th><th colspan="1" rowspan="1"><p>MMLU</p></th><th colspan="1" rowspan="1"><p>HellaSwag</p></th></tr><tr><td colspan="1" rowspan="1"><p>LLaMA 3 8B</p></td><td colspan="1" rowspan="1"><p>8B</p></td><td colspan="1" rowspan="1"><p>66.6</p></td><td colspan="1" rowspan="1"><p>82.0</p></td></tr><tr><td colspan="1" rowspan="1"><p>LLaMA 3 70B</p></td><td colspan="1" rowspan="1"><p>70B</p></td><td colspan="1" rowspan="1"><p>79.5</p></td><td colspan="1" rowspan="1"><p>87.3</p></td></tr><tr><td colspan="1" rowspan="1"><p>GPT-4</p></td><td colspan="1" rowspan="1"><p>~1.8T</p></td><td colspan="1" rowspan="1"><p>86.4</p></td><td colspan="1" rowspan="1"><p>95.3</p></td></tr><tr><td colspan="1" rowspan="1"><p>Mixtral 8x7B</p></td><td colspan="1" rowspan="1"><p>46.7B</p></td><td colspan="1" rowspan="1"><p>70.6</p></td><td colspan="1" rowspan="1"><p>84.4</p></td></tr></tbody></table><h2>Mathematics</h2><p>Inline math works with double dollars: the quadratic formula is <span data-latex="x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}" data-type="inline-math"></span> and Euler's identity is <span data-latex="e^{i\pi} + 1 = 0" data-type="inline-math"></span>.</p><p>Block equations use triple dollars. Here is a standard autoregressive loss:</p><div data-latex="\mathcal{L}(\theta) = -\sum_{t=1}^{T} \log P(x_t \mid x_{<t}; \theta)" data-type="block-math"></div><p>And the full variational trajectory decomposition:</p><div data-latex="\begin{aligned} \log p_\theta(\mathcal{D}) &= \log \sum_{i=0}^N p_\theta((o,a)_i) \\ &= \log \sum_{i=0}^N \int_{\text{supp}(Z)} p_\theta((o,a)_i \mid z)\, p(z) \\ &= \log \sum_{i=0}^N \int_{\text{supp}(Z)} \frac{q_\theta(z \mid (o,a)_i)}{q_\theta(z \mid (o,a)_i)} \cdot p_\theta((o,a)_i \mid z)\, p(z) \\ &= \log \sum_{i=0}^N \mathbb{E}_{z \sim p_\theta(\bullet \mid (o,a)_i)} \left[ \frac{p(z)}{q_\theta(z \mid (o,a)_i)} \cdot p_\theta((o,a)_i \mid z) \right] \end{aligned}" data-type="block-math"></div><h2>Scientific references</h2><p>The editor supports academic citations. The Transformer architecture <span key="vaswani2017" label="[vaswani2017]" data-type="citation" class="citation-node">[vaswani2017]</span> revolutionized natural language processing by introducing the self-attention mechanism. Large-scale pretraining <span key="devlin2019" label="[devlin2019]" data-type="citation" class="citation-node">[devlin2019]</span> demonstrated that unsupervised objectives on massive corpora produce powerful general-purpose representations.</p><p>More recently, scaling laws <span key="kaplan2020" label="[kaplan2020]" data-type="citation" class="citation-node">[kaplan2020]</span> have shown predictable relationships between model size, dataset size, and performance.</p><hr><h2>Horizontal rule</h2><p>Use a horizontal rule to visually separate sections:</p><hr><h2>Nested content</h2><p>Lists can contain multiple levels of formatting. Blockquotes can hold structured content:</p><blockquote><p><strong>Note:</strong> This editor supports real-time collaboration. Open this page in another tab to see cursors sync live.</p></blockquote><h3>A deeper heading level</h3><p>Heading levels go from H1 down to H3, giving you a clear document hierarchy. The floating menu on the left lets you insert any block type, and the bubble toolbar appears when you select text.</p><h2>Custom components</h2><p>The editor supports rich custom components from the research article template. Use the <code>/</code> slash menu to insert them.</p><details data-component="accordion"> | |
| <summary>Details</summary> | |
| <div class="accordion-content"><p>The model was fine-tuned using LoRA adapters with rank 16 on 4× A100 GPUs. Training took approximately 12 hours on the full dataset. We used a cosine learning rate schedule with warm-up over the first 10% of steps.</p></div> | |
| </details><div title="Important" emoji="💡" variant="info" data-component="note"><p>All experiments were conducted with mixed-precision (bf16) training. Results may vary slightly with different random seeds.</p></div><div author="Ilya Sutskever" source="NeurIPS 2024 keynote" data-component="quoteBlock"><p>If you have a very large neural network and you train it on a very large dataset, you get very good results. It really is that simple.</p></div><div title="Warning" emoji="⚠️" variant="danger" data-component="note"><p>Do not use these scaling estimates for production capacity planning without accounting for inference overhead and memory constraints.</p></div><div data-component="wide"><p>This content stretches beyond the normal column width, useful for wide tables, figures or visualizations that need extra horizontal space.</p></div><div data-component="fullWidth"><p>This content spans the entire page width. It is ideal for large figures, panoramic images, or full-bleed data visualizations.</p></div><div data-component="sidenote"><p>Scaling laws were first systematically studied in the context of neural machine translation before being generalized to language models.</p></div><div id="fig-scaling" caption="Log-linear relationship between compute budget and model performance across three orders of magnitude." data-component="reference"><p>[ Figure placeholder — insert an image or chart here ]</p></div><div src="d3-scaling-chart.html" title="Interactive scaling law visualization" desc="Explore how model size, data, and compute interact." wide="false" downloadable="true" data-component="htmlEmbed"></div><p>The concept of <span term="Scaling law" definition="A power-law relationship between model size, dataset size, compute budget, and performance." data-type="glossary" class="glossary-node" title="A power-law relationship between model size, dataset size, compute budget, and performance." tabindex="0">Scaling law</span> has become central to modern AI research. Early work<span content="Hestness et al. (2017) observed similar scaling behavior in vision and translation tasks before the scaling laws paper formalized the framework." data-type="footnote" class="footnote-node" title="Hestness et al. (2017) observed similar scaling behavior in vision and translation tasks before the scaling laws paper formalized the framework." tabindex="0"><sup class="footnote-marker">*</sup></span> suggested these relationships hold across modalities.</p><div layout="2-column" gap="medium" data-component="stack"><div data-type="stack-column"><p><strong>Column A</strong></p><p>Multi-column layouts let you place content side by side. Each column is fully editable.</p></div><div data-type="stack-column"><p><strong>Column B</strong></p><p>Use the layout selector in the header to switch between 2, 3, or 4 columns.</p></div></div><div username="tfrere" name="Thibaud Frere" url="https://huggingface.co/tfrere" data-component="hfUser"></div><h2>What's next?</h2><p>Try asking the AI assistant to:</p><ul><li><p>Rewrite a paragraph in a different tone</p></li><li><p>Expand a section with more detail</p></li><li><p>Fix grammar or spelling errors</p></li><li><p>Translate content to another language</p></li><li><p>Add a new section on a specific topic</p></li></ul><p>Select some text and use the quick actions, or type a message in the chat panel. All AI edits can be undone with <code>Cmd+Z</code>.</p><div data-type="bibliography" class="bibliography-block"><h2 class="bibliography-title">References</h2><div class="bibliography-content"><div class="csl-bib-body"> | |
| <div data-csl-entry-id="devlin2019" class="csl-entry">Devlin, J., Chang, M.-W., Lee, K., & Toutanova, K. (2019). BERT: Pre-training of deep bidirectional transformers for language understanding. <i>Proceedings of NAACL-HLT</i>, 4171–4186. https://doi.org/10.18653/v1/N19-1423</div> | |
| <div data-csl-entry-id="kaplan2020" class="csl-entry">Kaplan, J., McCandlish, S., Henighan, T., Brown, T. B., Chess, B., Child, R., Gray, S., Radford, A., Wu, J., & Amodei, D. (2020). Scaling laws for neural language models. <i>arXiv Preprint arXiv:2001.08361</i>. https://doi.org/10.48550/arXiv.2001.08361</div> | |
| <div data-csl-entry-id="vaswani2017" class="csl-entry">Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, L., & Polosukhin, I. (2017). Attention is all you need. <i>Advances in Neural Information Processing Systems</i>, <i>30</i>. https://doi.org/10.48550/arXiv.1706.03762</div> | |
| </div></div></div><p></p> | |
| </div> | |
| </article> | |
| </section> | |
| <!-- Image lightbox --> | |
| <dialog class="lightbox" id="lightbox"> | |
| <img id="lightbox-img" src="" alt=""> | |
| </dialog> | |
| <script> | |
| (function() { | |
| // Theme | |
| window.toggleTheme = function() { | |
| var next = document.documentElement.getAttribute('data-theme') === 'dark' ? 'light' : 'dark'; | |
| document.documentElement.setAttribute('data-theme', next); | |
| localStorage.setItem('theme', next); | |
| }; | |
| var saved = localStorage.getItem('theme'); | |
| if (saved) document.documentElement.setAttribute('data-theme', saved); | |
| // Lightbox | |
| document.querySelectorAll('.tiptap img').forEach(function(img) { | |
| img.style.cursor = 'zoom-in'; | |
| img.addEventListener('click', function() { | |
| document.getElementById('lightbox-img').src = img.src; | |
| document.getElementById('lightbox').showModal(); | |
| }); | |
| }); | |
| document.getElementById('lightbox').addEventListener('click', function(e) { if (e.target === this) this.close(); }); | |
| // Glossary | |
| document.querySelectorAll('[data-type="glossary"]').forEach(function(el) { el.setAttribute('tabindex', '0'); }); | |
| // ---- Table of Contents ---- | |
| var holder = document.getElementById('toc-placeholder'); | |
| var holderMobile = document.getElementById('toc-mobile-placeholder'); | |
| var articleRoot = document.querySelector('.content-grid article'); | |
| if (!articleRoot) return; | |
| var headings = articleRoot.querySelectorAll('h2, h3, h4'); | |
| if (!headings.length) return; | |
| var headingsArr = Array.from(headings); | |
| // Unique IDs | |
| var usedIds = {}; | |
| var slugify = function(s) { return String(s||'').toLowerCase().trim().replace(/\s+/g,'_').replace(/[^a-z0-9_-]/g,''); }; | |
| headingsArr.forEach(function(h) { | |
| var id = (h.id||'').trim() || slugify(h.textContent) || 'section'; | |
| var c = id, n = 2; | |
| while (usedIds[c]) c = id+'-'+(n++); | |
| if (h.id !== c) h.id = c; | |
| usedIds[c] = true; | |
| }); | |
| // Build nested nav with data-heading-idx | |
| var nav = document.createElement('nav'); | |
| var ulStack = [document.createElement('ul')]; | |
| nav.appendChild(ulStack[0]); | |
| var levelOf = function(tag) { return tag==='H2'?2:tag==='H3'?3:4; }; | |
| var prev = 2, hIdx = 0; | |
| headingsArr.forEach(function(h) { | |
| var lvl = levelOf(h.tagName); | |
| while (lvl > prev) { var ul = document.createElement('ul'); var last = ulStack[ulStack.length-1].lastElementChild; if (last) last.appendChild(ul); ulStack.push(ul); prev++; } | |
| while (lvl < prev) { ulStack.pop(); prev--; } | |
| var li = document.createElement('li'); | |
| var a = document.createElement('a'); | |
| a.href = '#'+h.id; a.textContent = h.textContent; | |
| li.appendChild(a); | |
| li.setAttribute('data-heading-idx', String(hIdx++)); | |
| ulStack[ulStack.length-1].appendChild(li); | |
| }); | |
| if (holder) holder.appendChild(nav); | |
| var navClone = nav.cloneNode(true); | |
| if (holderMobile) holderMobile.appendChild(navClone); | |
| // Mark navs as collapsible | |
| nav.classList.add('toc-collapsible'); | |
| navClone.classList.add('toc-collapsible'); | |
| var allLinks = [].concat( | |
| holder ? Array.from(holder.querySelectorAll('a')) : [], | |
| holderMobile ? Array.from(holderMobile.querySelectorAll('a')) : [] | |
| ); | |
| // ---- Auto-collapse logic ---- | |
| var isMobile = window.matchMedia('(max-width: 1100px)'); | |
| function getItemsWithChildren(navEl) { | |
| if (!navEl) return []; | |
| return Array.from(navEl.querySelectorAll('li[data-heading-idx]')).filter(function(li) { | |
| return li.querySelector(':scope > ul'); | |
| }); | |
| } | |
| function getAncestorIndices(items, targetIdx) { | |
| var toExpand = {}; | |
| var activeLi = null; | |
| function find(li) { | |
| if (Number(li.getAttribute('data-heading-idx')) === targetIdx) return li; | |
| var ul = li.querySelector(':scope > ul'); | |
| if (!ul) return null; | |
| var children = ul.querySelectorAll(':scope > li[data-heading-idx]'); | |
| for (var i = 0; i < children.length; i++) { var f = find(children[i]); if (f) return f; } | |
| return null; | |
| } | |
| for (var i = 0; i < items.length; i++) { activeLi = find(items[i]); if (activeLi) break; } | |
| if (!activeLi) return toExpand; | |
| toExpand[targetIdx] = true; | |
| var cur = activeLi; | |
| while (cur) { | |
| var parent = cur.parentElement ? cur.parentElement.closest('li[data-heading-idx]') : null; | |
| if (parent) { toExpand[Number(parent.getAttribute('data-heading-idx'))] = true; cur = parent; } | |
| else break; | |
| } | |
| return toExpand; | |
| } | |
| function applyCollapseState(navEl, activeIdx) { | |
| if (!navEl) return; | |
| var items = getItemsWithChildren(navEl); | |
| var ancestors = getAncestorIndices(items, activeIdx); | |
| items.forEach(function(li) { | |
| var sub = li.querySelector(':scope > ul'); | |
| if (!sub) return; | |
| var idx = Number(li.getAttribute('data-heading-idx')); | |
| var allDesc = li.querySelectorAll('li[data-heading-idx]'); | |
| var related = [idx]; | |
| allDesc.forEach(function(d) { related.push(Number(d.getAttribute('data-heading-idx'))); }); | |
| var shouldExpand = related.some(function(i) { return ancestors[i]; }); | |
| if (shouldExpand) { | |
| li.classList.remove('collapsed'); | |
| sub.style.height = 'auto'; | |
| } else { | |
| li.classList.add('collapsed'); | |
| sub.style.height = '0px'; | |
| } | |
| }); | |
| } | |
| function expandAll(navEl) { | |
| if (!navEl) return; | |
| getItemsWithChildren(navEl).forEach(function(li) { | |
| li.classList.remove('collapsed'); | |
| var sub = li.querySelector(':scope > ul'); | |
| if (sub) sub.style.height = 'auto'; | |
| }); | |
| } | |
| // Initial state: collapse all except first section | |
| function initCollapse() { | |
| if (isMobile.matches) { | |
| expandAll(holder ? holder.querySelector('nav') : null); | |
| expandAll(holderMobile ? holderMobile.querySelector('nav') : null); | |
| } else { | |
| applyCollapseState(holder ? holder.querySelector('nav') : null, 0); | |
| applyCollapseState(holderMobile ? holderMobile.querySelector('nav') : null, 0); | |
| } | |
| } | |
| initCollapse(); | |
| isMobile.addEventListener('change', function() { | |
| if (isMobile.matches) { | |
| expandAll(holder ? holder.querySelector('nav') : null); | |
| expandAll(holderMobile ? holderMobile.querySelector('nav') : null); | |
| } else { | |
| applyCollapseState(holder ? holder.querySelector('nav') : null, prevActiveIdx); | |
| applyCollapseState(holderMobile ? holderMobile.querySelector('nav') : null, prevActiveIdx); | |
| } | |
| }); | |
| // ---- Scroll tracking ---- | |
| var OFFSET = 60, lastScrollTime = 0, prevActiveIdx = 0; | |
| function onScroll() { | |
| var now = performance.now(); | |
| if (now - lastScrollTime < 50) return; | |
| lastScrollTime = now; | |
| requestAnimationFrame(function() { | |
| var activeIdx = -1, activeId = null; | |
| for (var i = headingsArr.length - 1; i >= 0; i--) { | |
| if (headingsArr[i].getBoundingClientRect().top - OFFSET <= 0) { | |
| activeIdx = i; activeId = headingsArr[i].id; break; | |
| } | |
| } | |
| allLinks.forEach(function(l) { | |
| if (activeId && l.getAttribute('href') === '#'+activeId) l.classList.add('active'); | |
| else l.classList.remove('active'); | |
| }); | |
| if (activeIdx !== prevActiveIdx && activeIdx >= 0 && !isMobile.matches) { | |
| prevActiveIdx = activeIdx; | |
| applyCollapseState(holder ? holder.querySelector('nav') : null, activeIdx); | |
| } | |
| if (activeIdx >= 0) prevActiveIdx = activeIdx; | |
| }); | |
| } | |
| window.addEventListener('scroll', onScroll, { passive: true }); | |
| onScroll(); | |
| // ---- Mobile sidebar ---- | |
| var sidebar = document.querySelector('.toc-mobile-sidebar'); | |
| var backdrop = document.querySelector('.toc-mobile-backdrop'); | |
| var toggleBtn = document.querySelector('.toc-mobile-toggle'); | |
| var closeBtn = document.querySelector('.toc-mobile-sidebar__close'); | |
| function openSidebar() { | |
| sidebar.classList.add('open'); backdrop.classList.add('open'); | |
| toggleBtn.setAttribute('aria-expanded','true'); | |
| document.body.style.overflow = 'hidden'; | |
| requestAnimationFrame(function() { | |
| var active = sidebar.querySelector('a.active'); | |
| if (active) { | |
| var body = sidebar.querySelector('.toc-mobile-sidebar__body'); | |
| if (body) body.scrollTop = Math.max(0, active.offsetTop - body.offsetTop - body.clientHeight/3); | |
| } | |
| }); | |
| } | |
| function closeSidebar() { | |
| sidebar.classList.remove('open'); backdrop.classList.remove('open'); | |
| toggleBtn.setAttribute('aria-expanded','false'); | |
| document.body.style.overflow = ''; | |
| } | |
| if (toggleBtn) toggleBtn.addEventListener('click', openSidebar); | |
| if (closeBtn) closeBtn.addEventListener('click', closeSidebar); | |
| if (backdrop) backdrop.addEventListener('click', closeSidebar); | |
| if (holderMobile) holderMobile.addEventListener('click', function(e) { if (e.target.closest && e.target.closest('a')) closeSidebar(); }); | |
| document.addEventListener('keydown', function(e) { if (e.key==='Escape' && sidebar.classList.contains('open')) closeSidebar(); }); | |
| // Hash navigation | |
| if (window.location.hash) { | |
| var target = document.querySelector(window.location.hash); | |
| if (target) setTimeout(function() { target.scrollIntoView({block:'start'}); }, 100); | |
| } | |
| window.addEventListener('popstate', function() { | |
| var h = window.location.hash; | |
| if (h) { var t = document.querySelector(h); if (t) t.scrollIntoView({block:'start'}); } | |
| else window.scrollTo({top:0}); | |
| }); | |
| })(); | |
| </script> | |
| </body> | |
| </html> |