✨ feat(remote_text shortcode): support line ranges (#399)
This commit is contained in:
parent
90c1da1ddb
commit
008b976e06
@ -207,6 +207,14 @@ dist/
|
|||||||
|
|
||||||
Afegeix text des d'una URL remota o un arxiu local.
|
Afegeix text des d'una URL remota o un arxiu local.
|
||||||
|
|
||||||
|
El shortcode accepta tres paràmetres:
|
||||||
|
|
||||||
|
- `src`: L'URL d'origen o ruta del fitxer (obligatori)
|
||||||
|
- `start`: Primera línia a mostrar (opcional, comença a 1)
|
||||||
|
- `end`: Número de l'última línia (opcional, per defecte és 0, l'última línia)
|
||||||
|
|
||||||
|
{{ admonition(type="info", text="`start` i `end` són inclusius. `start=3, end=3` mostrarà només la tercera línia.") }}
|
||||||
|
|
||||||
**Important**:
|
**Important**:
|
||||||
|
|
||||||
- **Arxius remots VS arxius locals**: Si `src` comença amb "http", es tractarà com un arxiu remot. D'altra banda, s'assumeix que és una ruta d'arxiu local.
|
- **Arxius remots VS arxius locals**: Si `src` comença amb "http", es tractarà com un arxiu remot. D'altra banda, s'assumeix que és una ruta d'arxiu local.
|
||||||
@ -229,6 +237,12 @@ Mostra el text d'un arxiu local:
|
|||||||
{{/* remote_text(src="ruta/a/arxiu.txt") */}}
|
{{/* remote_text(src="ruta/a/arxiu.txt") */}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Mostreu només les línies 3 a 5 d'un arxiu local:
|
||||||
|
|
||||||
|
```
|
||||||
|
{{/* remote_text(src="ruta/a/arxiu.txt", start=3, end=5) */}}
|
||||||
|
```
|
||||||
|
|
||||||
### Advertències
|
### Advertències
|
||||||
|
|
||||||
Destaca informació amb aquests shortcodes. Hi ha cinc tipus (`type`): `note`, `tip`, `info`, `warning`, i `danger`.
|
Destaca informació amb aquests shortcodes. Hi ha cinc tipus (`type`): `note`, `tip`, `info`, `warning`, i `danger`.
|
||||||
|
@ -208,6 +208,14 @@ dist/
|
|||||||
|
|
||||||
Añade texto desde una URL remota o un archivo local.
|
Añade texto desde una URL remota o un archivo local.
|
||||||
|
|
||||||
|
El shortcode acepta tres parámetros:
|
||||||
|
|
||||||
|
- `src`: La URL de origen o ruta del archivo (obligatorio)
|
||||||
|
- `start`: Primera línea a mostrar (opcional, empieza en 1)
|
||||||
|
- `end`: Número de la última línea (opcional, por defecto es 0, la última línea)
|
||||||
|
|
||||||
|
{{ admonition(type="info", text="`start` y `end` son inclusivos. `start=3, end=3` mostrará solo la tercera línea.") }}
|
||||||
|
|
||||||
**Importante**:
|
**Importante**:
|
||||||
|
|
||||||
- **Archivos remotos VS archivos locales**: Si `src` empieza con "http", se tratará como un archivo remoto. De lo contrario, se asume que es una ruta de archivo local.
|
- **Archivos remotos VS archivos locales**: Si `src` empieza con "http", se tratará como un archivo remoto. De lo contrario, se asume que es una ruta de archivo local.
|
||||||
@ -230,6 +238,12 @@ Visualización de texto de un archivo local:
|
|||||||
{{/* remote_text(src="ruta/a/archivo.txt") */}}
|
{{/* remote_text(src="ruta/a/archivo.txt") */}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Mostar sólo las líneas 3 a 5 de un archivo remoto:
|
||||||
|
|
||||||
|
```
|
||||||
|
{{/* remote_text(src="https://example.com/script.py", start=3, end=5) */}}
|
||||||
|
```
|
||||||
|
|
||||||
### Advertencias
|
### Advertencias
|
||||||
|
|
||||||
Destaca información con estos shortcodes. Hay cinco tipos (`type`): `note`, `tip`, `info`, `warning`, y `danger`.
|
Destaca información con estos shortcodes. Hay cinco tipos (`type`): `note`, `tip`, `info`, `warning`, y `danger`.
|
||||||
|
@ -207,6 +207,14 @@ dist/
|
|||||||
|
|
||||||
Embed text from a remote URL or a local file. To display the path or URL on the code block, see the [show source or path shortcode](#show-source-or-path).
|
Embed text from a remote URL or a local file. To display the path or URL on the code block, see the [show source or path shortcode](#show-source-or-path).
|
||||||
|
|
||||||
|
The shortcode accepts three parameters:
|
||||||
|
|
||||||
|
- `src`: The source URL or file path (required)
|
||||||
|
- `start`: First line to display (optional, starts at 1)
|
||||||
|
- `end`: The ending line number (optional, defaults to 0, meaning the last line)
|
||||||
|
|
||||||
|
{{ admonition(type="info", text="`start` and `end` are inclusive. `start=3, end=3` will display only the third line.") }}
|
||||||
|
|
||||||
**Important**:
|
**Important**:
|
||||||
|
|
||||||
- **Remote VS local files**: If `src` starts with "http", it will be treated as a remote file. Otherwise, it assumes a local file path.
|
- **Remote VS local files**: If `src` starts with "http", it will be treated as a remote file. Otherwise, it assumes a local file path.
|
||||||
@ -229,6 +237,12 @@ Displaying text from a local file:
|
|||||||
{{/* remote_text(src="path/to/file.txt") */}}
|
{{/* remote_text(src="path/to/file.txt") */}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Display lines 3 to 7 (both inclusive) of a local file:
|
||||||
|
|
||||||
|
```
|
||||||
|
{{/* remote_text(src="path/to/file.txt", start=3, end=7) */}}
|
||||||
|
```
|
||||||
|
|
||||||
### Admonitions
|
### Admonitions
|
||||||
|
|
||||||
Bring attention to information with these admonition shortcodes. They come in five `type`s: `note`, `tip`, `info`, `warning`, and `danger`.
|
Bring attention to information with these admonition shortcodes. They come in five `type`s: `note`, `tip`, `info`, `warning`, and `danger`.
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
{%- set start = start | default(value=1) -%}
|
||||||
|
{%- set end = end | default(value=0) -%}
|
||||||
|
|
||||||
{#- load_data uses different arguments based on whether it's a remote or local file -#}
|
{#- load_data uses different arguments based on whether it's a remote or local file -#}
|
||||||
{%- if src is starting_with("http") -%}
|
{%- if src is starting_with("http") -%}
|
||||||
{%- set response = load_data(url=src, format="plain") -%}
|
{%- set response = load_data(url=src, format="plain") -%}
|
||||||
@ -11,4 +14,17 @@
|
|||||||
{%- set response = load_data(path=src, format="plain") -%}
|
{%- set response = load_data(path=src, format="plain") -%}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{{- response | trim_end | safe -}}
|
|
||||||
|
{%- set lines = response | trim_end | split(pat="\n") -%}
|
||||||
|
|
||||||
|
{%- if start > 0 -%}
|
||||||
|
{%- set start = start - 1 -%}
|
||||||
|
{%- endif -%}
|
||||||
|
|
||||||
|
{%- if end == 0 or end > lines | length -%}
|
||||||
|
{%- set end = lines | length -%}
|
||||||
|
{%- endif -%}
|
||||||
|
|
||||||
|
{%- set lines = lines | slice(start=start, end=end) -%}
|
||||||
|
|
||||||
|
{{- lines | join(sep="\n") | safe -}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user