Skip to content

Commit 200cc0f

Browse files
authored
feat: add support for stretch tables (#701)
- Updated README.md to include a new section on stretch tables, explaining how to use the feature. - Enhanced mdsvex preprocessor to apply styles for tables that need to stretch to full width when the special flag is included in the markdown.
1 parent fb514b2 commit 200cc0f

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This is the package we use to build the documentation of our Hugging Face repos.
2626
+ [Anchor link](#anchor-link)
2727
+ [LaTeX](#latex)
2828
+ [Code Blocks](#code-blocks)
29+
+ [Stretch Tables](#stretch-tables)
2930
+ [Inference Snippet](#inference-snippet)
3031
* [Writing API documentation (Python)](#writing-api-documentation-python)
3132
+ [Autodoc](#autodoc)
@@ -504,6 +505,17 @@ Syntax:
504505

505506
Example: [here](https://github.com/huggingface/text-generation-inference/blob/724199aaf172590c3658018c0e6bc6152cda4c2f/docs/source/basic_tutorials/launcher.md?plain=1#L3)
506507

508+
### Stretch Tables
509+
510+
By default, tables in the documentation are sized to fit their content. If you want tables to stretch to the full width of the content area, you can add a special flag at the top of your mdx file.
511+
512+
Syntax:
513+
```
514+
<!-- STRETCH TABLES -->
515+
```
516+
517+
This will make all tables in that page expand to 100% width of the content container.
518+
507519
### Inference Snippet
508520

509521
The `InferenceSnippet` component is used to render an interactive interface for AI model inference. It uses [huggingface/huggingface.js](https://github.com/huggingface/huggingface.js) under the hood to get the snippets.

kit/preprocessors/mdsvex/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,22 @@ function renderCode(code) {
2222
);
2323
}
2424

25+
const STRETCH_TABLES_STYLES = `<style>
26+
:global(.prose table) {
27+
width: 100% !important;
28+
max-width: 100% !important;
29+
display: table !important;
30+
}
31+
</style>`;
32+
33+
function addStretchTablesStyles(code) {
34+
return code + "\n" + STRETCH_TABLES_STYLES;
35+
}
36+
2537
const WRAP_CODE_BLOCKS_FLAG = "<!-- WRAP CODE BLOCKS -->";
38+
const STRETCH_TABLES_FLAG = "<!-- STRETCH TABLES -->";
2639
let wrapCodeBlocks = false;
40+
let stretchTables = false;
2741

2842
export const mdsvexPreprocess = {
2943
markup: async ({ content, filename }) => {
@@ -33,11 +47,15 @@ export const mdsvexPreprocess = {
3347
// content = addCourseImports(content);
3448
// }
3549
wrapCodeBlocks = content.includes(WRAP_CODE_BLOCKS_FLAG);
50+
stretchTables = content.includes(STRETCH_TABLES_FLAG);
3651
content = markKatex(content, markedKatex);
3752
content = escapeSvelteConditionals(content);
3853
const processed = await _mdsvexPreprocess.markup({ content, filename });
3954
processed.code = renderKatex(processed.code, markedKatex);
4055
processed.code = renderCode(processed.code, filename);
56+
if (stretchTables) {
57+
processed.code = addStretchTablesStyles(processed.code);
58+
}
4159
return processed;
4260
}
4361
return { code: content };

0 commit comments

Comments
 (0)