From 382331857bbe982d4554b4f9336630654abe9bb3 Mon Sep 17 00:00:00 2001
From: Wim Looman
To recognize Docs.rs from
").into())
+ }
+
+ fn is_safe(&self) -> bool {
+ true
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/web/source.rs b/src/web/source.rs
index 10cd9b931..13f50da47 100644
--- a/src/web/source.rs
+++ b/src/web/source.rs
@@ -24,6 +24,30 @@ struct File {
name: String,
/// The mime type of the file
mime: String,
+ /// The extension of the file, if it has one
+ extension: Option{highlighted}
Setting a README
Detecting Docs.rs
build.rs
files, you can test for the environment variable DOCS_RS
, e.g.:
- {% filter dedent(levels=3) -%}
-
- {%- endfilter %}
+ }
+ {%- endfilter %}{% endfilter %}
This approach can be helpful if you need dependencies for building the library, but not for building the documentation.
if std::env::var("DOCS_RS").is_ok() {
+ {% filter highlight(lang="rust") %}{% filter dedent(levels=3) -%}
+ if std::env::var("DOCS_RS").is_ok() {
// ... your code here ...
- }
You can configure how your crate is built by adding package metadata to your Cargo.toml
, e.g.:
- {% filter dedent -%}
-
[package.metadata.docs.rs]
- rustc-args = ["--cfg", "docsrs"]
- {%- endfilter %}
+ {% filter highlight(lang="toml") %}{% filter dedent -%}
+ [package.metadata.docs.rs]
+ rustc-args = ["--cfg", "docsrs"]
+ {%- endfilter %}{% endfilter %}
Here, the compiler arguments are set so that #[cfg(docsrs)]
(not to be confused with #[cfg(doc)]
) can be used for conditional compilation.
This approach is also useful for setting cargo features.
@@ -107,11 +107,3 @@ The available configuration flags you can customize are:
-{%- include "core/Cargo.toml.example" -%}
+ {% filter highlight(lang="toml") %}
+ {%- include "core/Cargo.toml.example" -%}
+ {% endfilter %}
{%- endblock body %}
-
-{% block css -%}
- {{ macros::highlight_css() }}
-{%- endblock css %}
-
-{% block javascript -%}
- {{ macros::highlight_js(languages=["ini"]) }}
-{%- endblock javascript %}
diff --git a/templates/crate/details.html b/templates/crate/details.html
index 9fb08caa9..bf8c280bf 100644
--- a/templates/crate/details.html
+++ b/templates/crate/details.html
@@ -194,12 +194,3 @@
{%- endblock body -%}
-
-{%- block css -%}
- {{ macros::highlight_css() }}
-{%- endblock css -%}
-
-{%- block javascript -%}
- {# Enable and load Rust and TOML syntax highlighting #}
- {{ macros::highlight_js(languages=["rust", "ini"]) }}
-{% endblock javascript -%}
diff --git a/templates/crate/source.html b/templates/crate/source.html
index cf1bc029c..2615290c7 100644
--- a/templates/crate/source.html
+++ b/templates/crate/source.html
@@ -113,21 +113,14 @@
{# If the file has content, then display it in a codeblock #}
{%- if file_content -%}
{{ file_content }}
+ {{- file_content | highlight(lang=file.extension) -}}
left | mid dle | right |
one | two |
]]>
+## ^^^ - punctuation.definition.tag.end - illegal
+
+
+## ^^^^^^^^^^^^^^^^ comment.block.html
+## ^^^^ punctuation.definition.comment.begin.html
+## ^^^ punctuation.definition.comment.end.html
+## ^^^^^^^^^ - punctuation
+
+
+## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block - invalid.illegal.bad-comments-or-CDATA
+
+ -- hyphens
+## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block
+## ^ invalid.illegal.bad-comments-or-CDATA
+## ^^^^ invalid.illegal.bad-comments-or-CDATA
+## ^^^^ invalid.illegal.bad-comments-or-CDATA
+## ^^^ invalid.illegal.bad-comments-or-CDATA
+
+ - hyphens
+## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block
+## ^^ invalid.illegal.bad-comments-or-CDATA
+## ^^^^^^^^^^^^^^^ - invalid.illegal.bad-comments-or-CDATA
+
+
+| ^^^^^^ meta.disable-markdown meta.tag.script.end.html entity.name.tag.script.html
+okay
+| <- - meta.disable-markdown
+
+http://spec.commonmark.org/0.28/#example-139
+
+
+| ^^^^^ meta.disable-markdown meta.tag.style.end.html entity.name.tag.style.html
+okay
+| <- - meta.disable-markdown
+
+http://spec.commonmark.org/0.28/#example-143
+
+
+| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.disable-markdown
+*foo*
+| <- - meta.disable-markdown
+
+http://spec.commonmark.org/0.28/#example-144
+
+*bar*
+| ^^^^^^^^^^ comment.block.html
+| ^^^^^ meta.disable-markdown
+*baz*
+| <- - meta.disable-markdown
+
+http://spec.commonmark.org/0.28/#example-145
+
+1. *bar*
+| ^^^^^^^^^^^^^^^^ meta.disable-markdown
+okay
+| <- - meta.disable-markdown
+
+http://spec.commonmark.org/0.28/#example-146
+
+
+| ^^^^^^^^ meta.disable-markdown comment.block.html
+okay
+| <- - meta.disable-markdown
+
+http://spec.commonmark.org/0.28/#example-147
+
+';
+
+?>
+|^^ meta.disable-markdown
+okay
+| <- - meta.disable-markdown
+
+http://spec.commonmark.org/0.28/#example-148
+
+
+| ^^^^^^^ meta.disable-markdown meta.tag.sgml.doctype.html keyword.declaration.doctype.html
+okay
+| <- - meta.disable-markdown
+
+http://spec.commonmark.org/0.28/#example-149
+
+
+|^ meta.disable-markdown meta.tag.sgml.cdata.html
+okay
+| <- - meta.disable-markdown
+
+1. Test
+
+ ```python
+| ^^^ markup.list.numbered meta.code-fence punctuation.definition.raw.code-fence.begin
+ Test
+
+| <- - invalid
+ Test
+ ```
+| ^^^ punctuation.definition.raw.code-fence.end
+
+1. Test 2
+|^ markup.list.numbered.bullet punctuation.definition.list_item
+
+```xml
+|^^^^^ meta.code-fence.definition.begin.xml
+| ^^^ constant.other.language-name
+
+|^^^^^^^^^^^^^^^^^^^^^^ markup.raw.code-fence.xml
+| ^^^^^^^ meta.tag.preprocessor.xml entity.other.attribute-name.localname.xml
+
+ - match: (C)(<)
+ captures:
+ 1: entity.name.tag.code.perl
+ 2: punctuation.definition.tag.begin.perl
+ push:
+ - meta_content_scope: markup.quote.perl
+ - include: comment-pod-format-body
+ # escaped character : E
+ - match: (E)(<)
+ captures:
+ 1: entity.name.tag.escaped.perl
+ 2: punctuation.definition.tag.begin.perl
+ push:
+ - meta_content_scope: constant.character.escape.perl
+ - include: comment-pod-format-body
+ # italic text : I
+ - match: (I)(<)
+ captures:
+ 1: entity.name.tag.italic.perl
+ 2: punctuation.definition.tag.begin.perl
+ push:
+ - meta_content_scope: markup.italic.perl
+ - include: comment-pod-format-body
+ # filename : F
+ - match: (F)(<)
+ captures:
+ 1: entity.name.tag.filename.perl
+ 2: punctuation.definition.tag.begin.perl
+ push:
+ - meta_content_scope: meta.string.perl string.unquoted.perl
+ - include: comment-pod-format-body
+ # hyperlink : L