mirror of
https://github.com/typst/typst
synced 2025-07-29 15:27:53 +08:00
Compare commits
7 Commits
e8e8a05a8b
...
aaffc4212a
Author | SHA1 | Date | |
---|---|---|---|
|
aaffc4212a | ||
|
b790c6d59c | ||
|
b1c79b50d4 | ||
|
4629ede020 | ||
|
ccabbe5bec | ||
|
b374aa131b | ||
|
c69c07fab5 |
@ -173,8 +173,11 @@ typst help
|
|||||||
typst help watch
|
typst help watch
|
||||||
```
|
```
|
||||||
|
|
||||||
If you prefer an integrated IDE-like experience with autocompletion and instant
|
If you prefer an integrated IDE-like experience with autocompletion and instant
|
||||||
preview, you can also check out [Typst's free web app][app].
|
preview, you can also check out our [free web app][app]. Alternatively, there is
|
||||||
|
a community-created language server called
|
||||||
|
[Tinymist](https://myriad-dreamin.github.io/tinymist/) which is integrated into
|
||||||
|
various editor extensions.
|
||||||
|
|
||||||
## Community
|
## Community
|
||||||
The main places where the community gathers are our [Forum][forum] and our
|
The main places where the community gathers are our [Forum][forum] and our
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use crate::fragment::html_fragment;
|
||||||
|
use crate::{attr, tag, FrameElem, HtmlElem, HtmlElement, HtmlFrame, HtmlNode};
|
||||||
use typst_library::diag::{warning, SourceResult};
|
use typst_library::diag::{warning, SourceResult};
|
||||||
use typst_library::engine::Engine;
|
use typst_library::engine::Engine;
|
||||||
use typst_library::foundations::{Content, StyleChain, Target, TargetElem};
|
use typst_library::foundations::{Content, StyleChain, Target, TargetElem};
|
||||||
@ -5,10 +7,10 @@ use typst_library::introspection::{SplitLocator, TagElem};
|
|||||||
use typst_library::layout::{Abs, Axes, BlockBody, BlockElem, BoxElem, Region, Size};
|
use typst_library::layout::{Abs, Axes, BlockBody, BlockElem, BoxElem, Region, Size};
|
||||||
use typst_library::model::ParElem;
|
use typst_library::model::ParElem;
|
||||||
use typst_library::routines::Pair;
|
use typst_library::routines::Pair;
|
||||||
use typst_library::text::{LinebreakElem, SmartQuoteElem, SpaceElem, TextElem};
|
use typst_library::text::{
|
||||||
|
is_default_ignorable, LinebreakElem, SmartQuoteElem, SmartQuoter, SmartQuotes,
|
||||||
use crate::fragment::html_fragment;
|
SpaceElem, TextElem,
|
||||||
use crate::{attr, tag, FrameElem, HtmlElem, HtmlElement, HtmlFrame, HtmlNode};
|
};
|
||||||
|
|
||||||
/// Converts realized content into HTML nodes.
|
/// Converts realized content into HTML nodes.
|
||||||
pub fn convert_to_nodes<'a>(
|
pub fn convert_to_nodes<'a>(
|
||||||
@ -16,9 +18,10 @@ pub fn convert_to_nodes<'a>(
|
|||||||
locator: &mut SplitLocator,
|
locator: &mut SplitLocator,
|
||||||
children: impl IntoIterator<Item = Pair<'a>>,
|
children: impl IntoIterator<Item = Pair<'a>>,
|
||||||
) -> SourceResult<Vec<HtmlNode>> {
|
) -> SourceResult<Vec<HtmlNode>> {
|
||||||
|
let mut quoter = SmartQuoter::new();
|
||||||
let mut output = Vec::new();
|
let mut output = Vec::new();
|
||||||
for (child, styles) in children {
|
for (child, styles) in children {
|
||||||
handle(engine, child, locator, styles, &mut output)?;
|
handle(engine, child, locator, styles, &mut quoter, &mut output)?;
|
||||||
}
|
}
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
@ -29,6 +32,7 @@ fn handle(
|
|||||||
child: &Content,
|
child: &Content,
|
||||||
locator: &mut SplitLocator,
|
locator: &mut SplitLocator,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
|
quoter: &mut SmartQuoter,
|
||||||
output: &mut Vec<HtmlNode>,
|
output: &mut Vec<HtmlNode>,
|
||||||
) -> SourceResult<()> {
|
) -> SourceResult<()> {
|
||||||
if let Some(elem) = child.to_packed::<TagElem>() {
|
if let Some(elem) = child.to_packed::<TagElem>() {
|
||||||
@ -95,10 +99,20 @@ fn handle(
|
|||||||
} else if let Some(elem) = child.to_packed::<LinebreakElem>() {
|
} else if let Some(elem) = child.to_packed::<LinebreakElem>() {
|
||||||
output.push(HtmlElement::new(tag::br).spanned(elem.span()).into());
|
output.push(HtmlElement::new(tag::br).spanned(elem.span()).into());
|
||||||
} else if let Some(elem) = child.to_packed::<SmartQuoteElem>() {
|
} else if let Some(elem) = child.to_packed::<SmartQuoteElem>() {
|
||||||
output.push(HtmlNode::text(
|
let double = elem.double.get(styles);
|
||||||
if elem.double.get(styles) { '"' } else { '\'' },
|
if elem.enabled.get(styles) {
|
||||||
child.span(),
|
let before = last_char(output);
|
||||||
));
|
let quotes = SmartQuotes::get(
|
||||||
|
elem.quotes.get_ref(styles),
|
||||||
|
styles.get(TextElem::lang),
|
||||||
|
styles.get(TextElem::region),
|
||||||
|
elem.alternative.get(styles),
|
||||||
|
);
|
||||||
|
let quote = quoter.quote(before, "es, double);
|
||||||
|
output.push(HtmlNode::text(quote, child.span()));
|
||||||
|
} else {
|
||||||
|
output.push(HtmlNode::text(if double { '"' } else { '\'' }, child.span()));
|
||||||
|
}
|
||||||
} else if let Some(elem) = child.to_packed::<FrameElem>() {
|
} else if let Some(elem) = child.to_packed::<FrameElem>() {
|
||||||
let locator = locator.next(&elem.span());
|
let locator = locator.next(&elem.span());
|
||||||
let style = TargetElem::target.set(Target::Paged).wrap();
|
let style = TargetElem::target.set(Target::Paged).wrap();
|
||||||
@ -120,6 +134,20 @@ fn handle(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the last non-default ignorable character from the passed nodes.
|
||||||
|
fn last_char(nodes: &[HtmlNode]) -> Option<char> {
|
||||||
|
for node in nodes.iter().rev() {
|
||||||
|
if let Some(c) = match node {
|
||||||
|
HtmlNode::Text(s, _) => s.chars().rev().find(|&c| !is_default_ignorable(c)),
|
||||||
|
HtmlNode::Element(e) => last_char(&e.children),
|
||||||
|
_ => None,
|
||||||
|
} {
|
||||||
|
return Some(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks whether the given element is an inline-level HTML element.
|
/// Checks whether the given element is an inline-level HTML element.
|
||||||
pub fn is_inline(elem: &Content) -> bool {
|
pub fn is_inline(elem: &Content) -> bool {
|
||||||
elem.to_packed::<HtmlElem>()
|
elem.to_packed::<HtmlElem>()
|
||||||
|
@ -797,7 +797,9 @@ impl Color {
|
|||||||
components
|
components
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the constructor function for this color's space:
|
/// Returns the constructor function for this color's space.
|
||||||
|
///
|
||||||
|
/// Returns one of:
|
||||||
/// - [`luma`]($color.luma)
|
/// - [`luma`]($color.luma)
|
||||||
/// - [`oklab`]($color.oklab)
|
/// - [`oklab`]($color.oklab)
|
||||||
/// - [`oklch`]($color.oklch)
|
/// - [`oklch`]($color.oklch)
|
||||||
|
@ -242,7 +242,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
|||||||
items.push(CategoryItem {
|
items.push(CategoryItem {
|
||||||
name: group.name.clone(),
|
name: group.name.clone(),
|
||||||
route: subpage.route.clone(),
|
route: subpage.route.clone(),
|
||||||
oneliner: oneliner(docs).into(),
|
oneliner: oneliner(docs),
|
||||||
code: true,
|
code: true,
|
||||||
});
|
});
|
||||||
children.push(subpage);
|
children.push(subpage);
|
||||||
@ -296,7 +296,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
|||||||
items.push(CategoryItem {
|
items.push(CategoryItem {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
route: subpage.route.clone(),
|
route: subpage.route.clone(),
|
||||||
oneliner: oneliner(func.docs().unwrap_or_default()).into(),
|
oneliner: oneliner(func.docs().unwrap_or_default()),
|
||||||
code: true,
|
code: true,
|
||||||
});
|
});
|
||||||
children.push(subpage);
|
children.push(subpage);
|
||||||
@ -306,7 +306,7 @@ fn category_page(resolver: &dyn Resolver, category: Category) -> PageModel {
|
|||||||
items.push(CategoryItem {
|
items.push(CategoryItem {
|
||||||
name: ty.short_name().into(),
|
name: ty.short_name().into(),
|
||||||
route: subpage.route.clone(),
|
route: subpage.route.clone(),
|
||||||
oneliner: oneliner(ty.docs()).into(),
|
oneliner: oneliner(ty.docs()),
|
||||||
code: true,
|
code: true,
|
||||||
});
|
});
|
||||||
children.push(subpage);
|
children.push(subpage);
|
||||||
@ -637,7 +637,7 @@ fn group_page(
|
|||||||
let item = CategoryItem {
|
let item = CategoryItem {
|
||||||
name: group.name.clone(),
|
name: group.name.clone(),
|
||||||
route: model.route.clone(),
|
route: model.route.clone(),
|
||||||
oneliner: oneliner(&group.details).into(),
|
oneliner: oneliner(&group.details),
|
||||||
code: false,
|
code: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -772,8 +772,24 @@ pub fn urlify(title: &str) -> EcoString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the first line of documentation.
|
/// Extract the first line of documentation.
|
||||||
fn oneliner(docs: &str) -> &str {
|
fn oneliner(docs: &str) -> EcoString {
|
||||||
docs.lines().next().unwrap_or_default()
|
let paragraph = docs.split("\n\n").next().unwrap_or_default();
|
||||||
|
let mut depth = 0;
|
||||||
|
let mut period = false;
|
||||||
|
let mut end = paragraph.len();
|
||||||
|
for (i, c) in paragraph.char_indices() {
|
||||||
|
match c {
|
||||||
|
'(' | '[' | '{' => depth += 1,
|
||||||
|
')' | ']' | '}' => depth -= 1,
|
||||||
|
'.' if depth == 0 => period = true,
|
||||||
|
c if period && c.is_whitespace() && !docs[..i].ends_with("e.g.") => {
|
||||||
|
end = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => period = false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EcoString::from(&docs[..end]).replace("\r\n", " ").replace("\n", " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The order of types in the documentation.
|
/// The order of types in the documentation.
|
||||||
|
@ -86,7 +86,7 @@ pub struct FuncModel {
|
|||||||
pub name: EcoString,
|
pub name: EcoString,
|
||||||
pub title: &'static str,
|
pub title: &'static str,
|
||||||
pub keywords: &'static [&'static str],
|
pub keywords: &'static [&'static str],
|
||||||
pub oneliner: &'static str,
|
pub oneliner: EcoString,
|
||||||
pub element: bool,
|
pub element: bool,
|
||||||
pub contextual: bool,
|
pub contextual: bool,
|
||||||
pub deprecation: Option<&'static str>,
|
pub deprecation: Option<&'static str>,
|
||||||
@ -139,7 +139,7 @@ pub struct TypeModel {
|
|||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub title: &'static str,
|
pub title: &'static str,
|
||||||
pub keywords: &'static [&'static str],
|
pub keywords: &'static [&'static str],
|
||||||
pub oneliner: &'static str,
|
pub oneliner: EcoString,
|
||||||
pub details: Html,
|
pub details: Html,
|
||||||
pub constructor: Option<FuncModel>,
|
pub constructor: Option<FuncModel>,
|
||||||
pub scope: Vec<FuncModel>,
|
pub scope: Vec<FuncModel>,
|
||||||
|
@ -127,6 +127,10 @@
|
|||||||
checks = self'.checks;
|
checks = self'.checks;
|
||||||
inputsFrom = [ typst ];
|
inputsFrom = [ typst ];
|
||||||
|
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
rust-analyzer
|
||||||
|
];
|
||||||
|
|
||||||
packages = [
|
packages = [
|
||||||
# A script for quickly running tests.
|
# A script for quickly running tests.
|
||||||
# See https://github.com/typst/typst/blob/main/tests/README.md#making-an-alias
|
# See https://github.com/typst/typst/blob/main/tests/README.md#making-an-alias
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>Heading is no paragraph</h2>
|
<h2>Heading is no paragraph</h2>
|
||||||
<p>I'm a paragraph.</p>
|
<p>I’m a paragraph.</p>
|
||||||
<div>I'm not.</div>
|
<div>I’m not.</div>
|
||||||
<div>
|
<div>
|
||||||
<p>We are two.</p>
|
<p>We are two.</p>
|
||||||
<p>So we are paragraphs.</p>
|
<p>So we are paragraphs.</p>
|
||||||
|
@ -5,6 +5,6 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>When you said that “he surely meant that ‘she intended to say “I'm sorry”’”, I was quite confused.</p>
|
<p>When you said that “he surely meant that ‘she intended to say “I’m sorry”’”, I was quite confused.</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
11
tests/ref/html/smartquotes-html.html
Normal file
11
tests/ref/html/smartquotes-html.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>When you said that “he surely meant that ‘she intended to say “I’m sorry”’”, I was quite confused.</p>
|
||||||
|
<p>‘<span style="display: inline-block;">box</span>’</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -172,3 +172,8 @@ Some people's thought on this would be #[#set smartquote(enabled: false); "stran
|
|||||||
|
|
||||||
--- issue-5146-smartquotes-after-equations ---
|
--- issue-5146-smartquotes-after-equations ---
|
||||||
$i$'s $i$ 's
|
$i$'s $i$ 's
|
||||||
|
|
||||||
|
--- smartquotes-html html ---
|
||||||
|
When you said that "he surely meant that 'she intended to say "I'm sorry"'", I was quite confused.
|
||||||
|
|
||||||
|
'#box[box]'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user