Questa pagina è stata tradotta automaticamente dalla documentazione ufficiale, che si trova in https://vaadin.com/docs. Potrebbe contenere errori, inesattezze, o affermazioni non corrette. Vaadin non garantisce né rilascia alcuna dichiarazione riguardo l’accuratezza, l’affidabilità, o la tempestività della traduzione.
Il componente Markdown renderizza contenuto scritto nella sintassi Markdown come HTML.
Supporta la formattazione di base del testo, elenchi, link, e altro. Tutto il contenuto fornito al componente viene sanitizzato internamente per impedire che venga renderizzato HTML potenzialmente pericoloso.
Per ulteriori informazioni sulle funzionalità comuni della sintassi Markdown, consulti la Markdown Guide.
package com.vaadin.demo.component.markdown;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.markdown.Markdown;
import com.vaadin.flow.router.Route;
@Route("markdown-basic")
public class MarkdownBasic extends Div {
public MarkdownBasic() {
// tag::snippet[]
String markdownText = """
## Rich Text Formatting
You can create **bold text**, *italicized text*, and `inline code` with simple Markdown syntax.
You can also ~~strike through~~ text when needed.
## Lists
### Ordered List:
1. First item
2. Second item
3. Third item with **bold text**
### Unordered List:
- Fruits
- Apples 🍎
- Bananas 🍌
- Oranges 🍊
- Vegetables
- Carrots
- Broccoli
## Links & Quotes
> Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents.
[Visit Vaadin website](https://vaadin.com) | [Learn more about Markdown](https://www.markdownguide.org/)
""";
Markdown markdown = new Markdown(markdownText);
add(markdown);
// end::snippet[]
}
}
markdown-basic.tsx
import React from 'react';
import { Markdown } from '@vaadin/react-components/Markdown.js';
function Example() {
// tag::snippet[]
const markdownText = `
## Rich Text Formatting
You can create **bold text**, *italicized text*, and \`inline code\` with simple Markdown syntax.
You can also ~~strike through~~ text when needed.
## Lists
### Ordered List:
1. First item
2. Second item
3. Third item with **bold text**
### Unordered List:
- Fruits
- Apples 🍎
- Bananas 🍌
- Oranges 🍊
- Vegetables
- Carrots
- Broccoli
## Links & Quotes
> Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents.
[Visit Vaadin website](https://vaadin.com) | [Learn more about Markdown](https://www.markdownguide.org/)
`;
return <Markdown>{markdownText}</Markdown>;
// end::snippet[]
}
markdown-basic.ts
import '@vaadin/markdown';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
import { applyTheme } from 'Frontend/demo/theme';
@customElement('markdown-basic')
export class MarkdownBasic extends LitElement {
protected override createRenderRoot() {
const root = super.createRenderRoot();
applyTheme(root);
return root;
}
protected override render() {
// tag::snippet[]
const markdownText = `
## Rich Text Formatting
You can create **bold text**, *italicized text*, and \`inline code\` with simple Markdown syntax.
You can also ~~strike through~~ text when needed.
## Lists
### Ordered List:
1. First item
2. Second item
3. Third item with **bold text**
### Unordered List:
- Fruits
- Apples 🍎
- Bananas 🍌
- Oranges 🍊
- Vegetables
- Carrots
- Broccoli
## Links & Quotes
> Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents.
[Visit Vaadin website](https://vaadin.com) | [Learn more about Markdown](https://www.markdownguide.org/)
`;
return html`<vaadin-markdown .content=${markdownText}></vaadin-markdown>`;
// end::snippet[]
}
}
Interruzioni di Riga
Per impostazione predefinita, il componente segue la specifica Markdown originale: una singola interruzione di riga all’interno di un paragrafo viene compressa in uno spazio, ed è necessaria una riga vuota per iniziare un nuovo paragrafo.
Abilitare l’opzione delle interruzioni di riga renderizza le singole interruzioni di riga (chiamate anche soft breaks) come vere interruzioni di riga, nel modo in cui tipicamente si comporta il Markdown in stile chat e messaggi. Le righe vuote avviano comunque un nuovo paragrafo.