From 28a905a224ff97f9ab19b0ad5ced38d761c19c9d Mon Sep 17 00:00:00 2001 From: David Campbell Date: Sun, 10 Nov 2024 00:24:15 -0500 Subject: [PATCH] Add djot support, make a test_djot_book folder. --- .gitignore | 1 + Cargo.lock | 7 + Cargo.toml | 1 + README.md | 5 +- src/preprocess/index.rs | 14 +- src/renderer/html_handlebars/hbs_renderer.rs | 28 +- src/utils/mod.rs | 14 + test_djot_book/book.toml | 27 + test_djot_book/src/README.dj | 24 + test_djot_book/src/SUMMARY.md | 50 + .../src/djot_specific_block/README.dj | 1 + test_djot_book/src/djot_specific_block/div.dj | 7 + .../src/djot_specific_block/footnote.dj | 5 + .../src/djot_specific_block/raw_block.dj | 9 + .../src/djot_specific_inline/README.dj | 1 + .../src/djot_specific_inline/comment.dj | 3 + .../src/djot_specific_inline/footnote.dj | 5 + .../src/djot_specific_inline/highlight.dj | 3 + .../djot_specific_inline/inline_attributes.dj | 3 + .../src/djot_specific_inline/insert.dj | 3 + .../src/djot_specific_inline/raw_inline.dj | 3 + .../src/djot_specific_inline/span.dj | 3 + .../src/djot_specific_inline/subscript.dj | 3 + .../src/djot_specific_inline/superscript.dj | 3 + .../src/djot_specific_inline/symbols.dj | 3 + test_djot_book/src/individual/README.dj | 17 + test_djot_book/src/individual/blockquote.dj | 30 + test_djot_book/src/individual/code.dj | 33 + test_djot_book/src/individual/emphasis.dj | 13 + test_djot_book/src/individual/heading.dj | 21 + test_djot_book/src/individual/image.dj | 27 + test_djot_book/src/individual/linebreak.dj | 8 + test_djot_book/src/individual/link_hr.dj | 16 + test_djot_book/src/individual/list.dj | 89 ++ test_djot_book/src/individual/mathjax.dj | 41 + test_djot_book/src/individual/mixed.dj | 65 ++ test_djot_book/src/individual/paragraph.dj | 25 + .../src/individual/strikethrough.dj | 7 + test_djot_book/src/individual/table.dj | 33 + test_djot_book/src/individual/task.dj | 11 + .../src/individual/thematic_break.dj | 17 + test_djot_book/src/languages/README.dj | 49 + test_djot_book/src/languages/highlight.dj | 956 ++++++++++++++++++ test_djot_book/src/prefix.dj | 3 + test_djot_book/src/rust/README.dj | 1 + test_djot_book/src/rust/rust_codeblock.dj | 27 + test_djot_book/src/suffix.dj | 3 + 47 files changed, 1708 insertions(+), 10 deletions(-) create mode 100644 test_djot_book/book.toml create mode 100644 test_djot_book/src/README.dj create mode 100644 test_djot_book/src/SUMMARY.md create mode 100644 test_djot_book/src/djot_specific_block/README.dj create mode 100644 test_djot_book/src/djot_specific_block/div.dj create mode 100644 test_djot_book/src/djot_specific_block/footnote.dj create mode 100644 test_djot_book/src/djot_specific_block/raw_block.dj create mode 100644 test_djot_book/src/djot_specific_inline/README.dj create mode 100644 test_djot_book/src/djot_specific_inline/comment.dj create mode 100644 test_djot_book/src/djot_specific_inline/footnote.dj create mode 100644 test_djot_book/src/djot_specific_inline/highlight.dj create mode 100644 test_djot_book/src/djot_specific_inline/inline_attributes.dj create mode 100644 test_djot_book/src/djot_specific_inline/insert.dj create mode 100644 test_djot_book/src/djot_specific_inline/raw_inline.dj create mode 100644 test_djot_book/src/djot_specific_inline/span.dj create mode 100644 test_djot_book/src/djot_specific_inline/subscript.dj create mode 100644 test_djot_book/src/djot_specific_inline/superscript.dj create mode 100644 test_djot_book/src/djot_specific_inline/symbols.dj create mode 100644 test_djot_book/src/individual/README.dj create mode 100644 test_djot_book/src/individual/blockquote.dj create mode 100644 test_djot_book/src/individual/code.dj create mode 100644 test_djot_book/src/individual/emphasis.dj create mode 100644 test_djot_book/src/individual/heading.dj create mode 100644 test_djot_book/src/individual/image.dj create mode 100644 test_djot_book/src/individual/linebreak.dj create mode 100644 test_djot_book/src/individual/link_hr.dj create mode 100644 test_djot_book/src/individual/list.dj create mode 100644 test_djot_book/src/individual/mathjax.dj create mode 100644 test_djot_book/src/individual/mixed.dj create mode 100644 test_djot_book/src/individual/paragraph.dj create mode 100644 test_djot_book/src/individual/strikethrough.dj create mode 100644 test_djot_book/src/individual/table.dj create mode 100644 test_djot_book/src/individual/task.dj create mode 100644 test_djot_book/src/individual/thematic_break.dj create mode 100644 test_djot_book/src/languages/README.dj create mode 100644 test_djot_book/src/languages/highlight.dj create mode 100644 test_djot_book/src/prefix.dj create mode 100644 test_djot_book/src/rust/README.dj create mode 100644 test_djot_book/src/rust/rust_codeblock.dj create mode 100644 test_djot_book/src/suffix.dj diff --git a/.gitignore b/.gitignore index a23c771e89..84d55a2051 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ guide/book .vscode tests/dummy_book/book/ test_book/book/ +test_djot_book/book/ # Ignore Jetbrains specific files. .idea/ diff --git a/Cargo.lock b/Cargo.lock index 299e8daa53..493f387c57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1001,6 +1001,12 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jotdown" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19fa1db3b285830176c8a940d4e3376679772bee9f58a83dd9285a4a54e30f6e" + [[package]] name = "js-sys" version = "0.3.72" @@ -1152,6 +1158,7 @@ dependencies = [ "futures-util", "handlebars", "ignore", + "jotdown", "log", "memchr", "notify", diff --git a/Cargo.toml b/Cargo.toml index 5d593b2700..2828d29f35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ clap_complete = "4.3.2" once_cell = "1.17.1" env_logger = "0.11.1" handlebars = "6.0" +jotdown = "0.6" log = "0.4.17" memchr = "2.5.0" opener = "0.7.0" diff --git a/README.md b/README.md index b2177cf307..58168f5bac 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,14 @@ [![crates.io](https://img.shields.io/crates/v/mdbook.svg)](https://crates.io/crates/mdbook) [![LICENSE](https://img.shields.io/github/license/rust-lang/mdBook.svg)](LICENSE) -mdBook is a utility to create modern online books from Markdown files. +mdBook is a utility to create modern online books from Markdown or Djot files. Check out the **[User Guide]** for a list of features and installation and usage information. The User Guide also serves as a demonstration to showcase what a book looks like. +If a file ends in .dj it will be treated as a djot file. Check out the test_djot_book for djot +specific markup. + If you are interested in contributing to the development of mdBook, check out the [Contribution Guide]. ## License diff --git a/src/preprocess/index.rs b/src/preprocess/index.rs index 004b7eda6e..90d17ec398 100644 --- a/src/preprocess/index.rs +++ b/src/preprocess/index.rs @@ -1,4 +1,5 @@ use regex::Regex; +use std::ffi::OsStr; use std::path::Path; use super::{Preprocessor, PreprocessorContext}; @@ -37,7 +38,16 @@ impl Preprocessor for IndexPreprocessor { warn_readme_name_conflict(&path, &&mut index_md); } - path.set_file_name("index.md"); + let mut index_dj = source_dir.join(path.with_file_name("index.dj")); + if index_dj.exists() { + warn_readme_name_conflict(&path, &&mut index_dj); + } + + if Some(OsStr::new("dj")) == path.extension() { + path.set_file_name("index.dj"); + } else { + path.set_file_name("index.md"); + } } } } @@ -54,7 +64,7 @@ fn warn_readme_name_conflict>(readme_path: P, index_path: P) { .parent() .unwrap_or_else(|| index_path.as_ref()); warn!( - "It seems that there are both {:?} and index.md under \"{}\".", + "It seems that there are both {:?} and index.md or index.dj under \"{}\".", file_name, parent_dir.display() ); diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index d0149fb523..4777ec4254 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -9,6 +9,7 @@ use crate::utils; use std::borrow::Cow; use std::collections::BTreeMap; use std::collections::HashMap; +use std::ffi::OsStr; use std::fs::{self, File}; use std::path::{Path, PathBuf}; @@ -54,13 +55,22 @@ impl HtmlHandlebars { .insert("git_repository_edit_url".to_owned(), json!(edit_url)); } - let content = utils::render_markdown(&ch.content, ctx.html_config.smart_punctuation()); + let content = if Some(OsStr::new("dj")) == path.extension() { + utils::render_djot(&ch.content)? + } else { + utils::render_markdown(&ch.content, ctx.html_config.smart_punctuation()) + }; + + let fixed_content = if Some(OsStr::new("dj")) == path.extension() { + utils::render_djot(&ch.content)? + } else { + utils::render_markdown_with_path( + &ch.content, + ctx.html_config.smart_punctuation(), + Some(path), + ) + }; - let fixed_content = utils::render_markdown_with_path( - &ch.content, - ctx.html_config.smart_punctuation(), - Some(path), - ); if !ctx.is_index && ctx.html_config.print.page_break { // Add page break between chapters // See https://developer.mozilla.org/en-US/docs/Web/CSS/break-before and https://developer.mozilla.org/en-US/docs/Web/CSS/page-break-before @@ -124,7 +134,11 @@ impl HtmlHandlebars { utils::fs::write_file(&ctx.destination, &filepath, rendered.as_bytes())?; if ctx.is_index { - ctx.data.insert("path".to_owned(), json!("index.md")); + if Some(OsStr::new("dj")) == path.extension() { + ctx.data.insert("path".to_owned(), json!("index.dj")); + } else { + ctx.data.insert("path".to_owned(), json!("index.md")); + } ctx.data.insert("path_to_root".to_owned(), json!("")); ctx.data.insert("is_index".to_owned(), json!(true)); let rendered_index = ctx.handlebars.render("index", &ctx.data)?; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index a53f79c0e9..735ebfade6 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -4,6 +4,7 @@ pub mod fs; mod string; pub(crate) mod toml_ext; use crate::errors::Error; +use jotdown::{html::Indentation, Render}; use log::error; use once_cell::sync::Lazy; use pulldown_cmark::{html, CodeBlockKind, CowStr, Event, Options, Parser, Tag, TagEnd}; @@ -189,6 +190,19 @@ fn adjust_links<'a>(event: Event<'a>, path: Option<&Path>) -> Event<'a> { } } +/// Wrapper around the jotdown parser for rendering djot to HTML. +pub fn render_djot(text: &str) -> anyhow::Result { + let events = jotdown::Parser::new(text); + let mut content = String::new(); + let renderer = jotdown::html::Renderer::indented(Indentation { + string: " ".repeat(4), + initial_level: 6, + }); + renderer.push(events, &mut content)?; + let content_stripped = content.trim().to_string(); + Ok(content_stripped) +} + /// Wrapper around the pulldown-cmark parser for rendering markdown to HTML. pub fn render_markdown(text: &str, smart_punctuation: bool) -> String { render_markdown_with_path(text, smart_punctuation, None) diff --git a/test_djot_book/book.toml b/test_djot_book/book.toml new file mode 100644 index 0000000000..a30500763c --- /dev/null +++ b/test_djot_book/book.toml @@ -0,0 +1,27 @@ +[book] +title = "mdBook test book" +description = "A demo book to test and validate changes" +authors = ["YJDoc2"] +language = "en" + +[rust] +edition = "2018" + +[output.html] +mathjax-support = true + +[output.html.playground] +editable = true +line-numbers = true + +[output.html.search] +limit-results = 20 +use-boolean-and = true +boost-title = 2 +boost-hierarchy = 2 +boost-paragraph = 1 +expand = true +heading-split-level = 2 + +[output.html.redirect] +"/format/config.html" = "configuration/index.html" diff --git a/test_djot_book/src/README.dj b/test_djot_book/src/README.dj new file mode 100644 index 0000000000..24584e1cfc --- /dev/null +++ b/test_djot_book/src/README.dj @@ -0,0 +1,24 @@ +# Demo Book + +This is a simple demo book, which is intended to be used for verifying and validating style changes in mdBook. +This contains dummy examples of various djot elements and code languages, so that one can check changes made in mdBook styles. + +This rough outline is : + +: individual + + contains basic djot elements such as headings, paragraphs, links etc. + +: languages + + contains a `hello world` in each of supported language to see changes in syntax highlighting + +: rust + + contains language examples specific to rust, such as play pen, runnable examples etc. + +: djot specific inline + + contains djot specific items that are inline. + +This is more for checking and fixing style, rather than verifying that correct code is generated for given djot, that is better handled in tests. diff --git a/test_djot_book/src/SUMMARY.md b/test_djot_book/src/SUMMARY.md new file mode 100644 index 0000000000..c5be211939 --- /dev/null +++ b/test_djot_book/src/SUMMARY.md @@ -0,0 +1,50 @@ +# Summary + +[Prefix Chapter](prefix.dj) + +--- + +- [Introduction](README.dj) +- [Draft Chapter]() + +# Actual Djot Tag Examples + +- [Djot Individual tags](individual/README.dj) + - [Heading](individual/heading.dj) + - [Paragraphs](individual/paragraph.dj) + - [Line Break](individual/linebreak.dj) + - [Emphasis](individual/emphasis.dj) + - [Blockquote](individual/blockquote.dj) + - [List](individual/list.dj) + - [Code](individual/code.dj) + - [Image](individual/image.dj) + - [Links and Horizontal Rule](individual/link_hr.dj) + - [Tables](individual/table.dj) + - [Tasks](individual/task.dj) + - [Strikethrough](individual/strikethrough.dj) + - [MathJax](individual/mathjax.dj) + - [Mixed](individual/mixed.dj) + - [Thematic Break](individual/thematic_break.dj) +- [Languages](languages/README.dj) + - [Syntax Highlight](languages/highlight.dj) +- [Rust Specific](rust/README.dj) + - [Rust Codeblocks](rust/rust_codeblock.dj) +- [Djot Specific Inline](djot_specific_inline/README.dj) + - [Comment](djot_specific_inline/comment.dj) + - [Footnote](djot_specific_inline/footnote.dj) + - [Highlight](djot_specific_inline/highlight.dj) + - [Inline Attributes](djot_specific_inline/inline_attributes.dj) + - [Insert](djot_specific_inline/insert.dj) + - [Raw Inline](djot_specific_inline/raw_inline.dj) + - [Span](djot_specific_inline/span.dj) + - [Subscript](djot_specific_inline/subscript.dj) + - [Superscript](djot_specific_inline/superscript.dj) + - [Symbols](djot_specific_inline/symbols.dj) +- [Djot Specific Block](djot_specific_block/README.dj) + - [Div](djot_specific_block/div.dj) + - [Raw Block](djot_specific_block/raw_block.dj) + - [Footnote](djot_specific_block/footnote.dj) + +--- + +[Suffix Chapter](suffix.dj) diff --git a/test_djot_book/src/djot_specific_block/README.dj b/test_djot_book/src/djot_specific_block/README.dj new file mode 100644 index 0000000000..d211453528 --- /dev/null +++ b/test_djot_book/src/djot_specific_block/README.dj @@ -0,0 +1 @@ +# Djot Specific Block diff --git a/test_djot_book/src/djot_specific_block/div.dj b/test_djot_book/src/djot_specific_block/div.dj new file mode 100644 index 0000000000..f943cefc36 --- /dev/null +++ b/test_djot_book/src/djot_specific_block/div.dj @@ -0,0 +1,7 @@ +# Div + +::: warning +Here is a paragraph. + +And here is another. +::: diff --git a/test_djot_book/src/djot_specific_block/footnote.dj b/test_djot_book/src/djot_specific_block/footnote.dj new file mode 100644 index 0000000000..e07e94a848 --- /dev/null +++ b/test_djot_book/src/djot_specific_block/footnote.dj @@ -0,0 +1,5 @@ +# Footnote + +Here's the reference.[^one] + +[^one]: This is a footnote. diff --git a/test_djot_book/src/djot_specific_block/raw_block.dj b/test_djot_book/src/djot_specific_block/raw_block.dj new file mode 100644 index 0000000000..32f32dde61 --- /dev/null +++ b/test_djot_book/src/djot_specific_block/raw_block.dj @@ -0,0 +1,9 @@ +# Raw Block + +``` =html +

a html paragraph

+``` + +``` =plaintext +a plaintext paragraph +``` diff --git a/test_djot_book/src/djot_specific_inline/README.dj b/test_djot_book/src/djot_specific_inline/README.dj new file mode 100644 index 0000000000..95c29e1b96 --- /dev/null +++ b/test_djot_book/src/djot_specific_inline/README.dj @@ -0,0 +1 @@ +# Djot Specific Inline diff --git a/test_djot_book/src/djot_specific_inline/comment.dj b/test_djot_book/src/djot_specific_inline/comment.dj new file mode 100644 index 0000000000..e75048b861 --- /dev/null +++ b/test_djot_book/src/djot_specific_inline/comment.dj @@ -0,0 +1,3 @@ +# Comment + +Here is a {% comment %}. diff --git a/test_djot_book/src/djot_specific_inline/footnote.dj b/test_djot_book/src/djot_specific_inline/footnote.dj new file mode 100644 index 0000000000..f79f6eb69a --- /dev/null +++ b/test_djot_book/src/djot_specific_inline/footnote.dj @@ -0,0 +1,5 @@ +# Footnote + +Here is a reference.[^ref] + +[^ref]: Here is a footnote. diff --git a/test_djot_book/src/djot_specific_inline/highlight.dj b/test_djot_book/src/djot_specific_inline/highlight.dj new file mode 100644 index 0000000000..10a26516d9 --- /dev/null +++ b/test_djot_book/src/djot_specific_inline/highlight.dj @@ -0,0 +1,3 @@ +# Highlight + +This is {=highlighted text=}. diff --git a/test_djot_book/src/djot_specific_inline/inline_attributes.dj b/test_djot_book/src/djot_specific_inline/inline_attributes.dj new file mode 100644 index 0000000000..5d8314f582 --- /dev/null +++ b/test_djot_book/src/djot_specific_inline/inline_attributes.dj @@ -0,0 +1,3 @@ +# Inline Attributes + +Inline attributes{.class #id key="value"} diff --git a/test_djot_book/src/djot_specific_inline/insert.dj b/test_djot_book/src/djot_specific_inline/insert.dj new file mode 100644 index 0000000000..8fc2169e27 --- /dev/null +++ b/test_djot_book/src/djot_specific_inline/insert.dj @@ -0,0 +1,3 @@ +# Insert + +{+insert+} diff --git a/test_djot_book/src/djot_specific_inline/raw_inline.dj b/test_djot_book/src/djot_specific_inline/raw_inline.dj new file mode 100644 index 0000000000..8d4f11e59d --- /dev/null +++ b/test_djot_book/src/djot_specific_inline/raw_inline.dj @@ -0,0 +1,3 @@ +# Raw Inline + +This is ``{=html}. diff --git a/test_djot_book/src/djot_specific_inline/span.dj b/test_djot_book/src/djot_specific_inline/span.dj new file mode 100644 index 0000000000..8d74b1c8bc --- /dev/null +++ b/test_djot_book/src/djot_specific_inline/span.dj @@ -0,0 +1,3 @@ +# Span + +This is a [span]{.wonderful}. diff --git a/test_djot_book/src/djot_specific_inline/subscript.dj b/test_djot_book/src/djot_specific_inline/subscript.dj new file mode 100644 index 0000000000..9f758822da --- /dev/null +++ b/test_djot_book/src/djot_specific_inline/subscript.dj @@ -0,0 +1,3 @@ +# Subscript + +sub~script~ diff --git a/test_djot_book/src/djot_specific_inline/superscript.dj b/test_djot_book/src/djot_specific_inline/superscript.dj new file mode 100644 index 0000000000..52b6ea45ff --- /dev/null +++ b/test_djot_book/src/djot_specific_inline/superscript.dj @@ -0,0 +1,3 @@ +# Superscript + +super^script^ diff --git a/test_djot_book/src/djot_specific_inline/symbols.dj b/test_djot_book/src/djot_specific_inline/symbols.dj new file mode 100644 index 0000000000..2242db24c2 --- /dev/null +++ b/test_djot_book/src/djot_specific_inline/symbols.dj @@ -0,0 +1,3 @@ +# Symbols + +Support for symbols is optional :+1: :smiley:! diff --git a/test_djot_book/src/individual/README.dj b/test_djot_book/src/individual/README.dj new file mode 100644 index 0000000000..3c16a5e07e --- /dev/null +++ b/test_djot_book/src/individual/README.dj @@ -0,0 +1,17 @@ +# Djot Individual tags + +This contains following tags: + +- Headings +- Paragraphs +- Line breaks +- Emphasis +- Blockquotes +- Lists +- Code blocks +- Images +- Links and Horizontal rules +- Tables +- Task Lists (not supported) +- Strikethrough +- Mixed diff --git a/test_djot_book/src/individual/blockquote.dj b/test_djot_book/src/individual/blockquote.dj new file mode 100644 index 0000000000..a75c94c678 --- /dev/null +++ b/test_djot_book/src/individual/blockquote.dj @@ -0,0 +1,30 @@ +# Blockquote + +> This is a quoted sentence. + +> This is a quoted paragraph +> +> separated lines +> here + +> Nested +> +> > Quoted +> > Paragraph + +> ### And now, +> +> *Let us _introduce_* +> All kinds of +> +> - tags +> - etc +> - stuff +> +> 1. In +> 2. The +> 3. blockquote +> +> > cause we can +> > +> > > Cause we can diff --git a/test_djot_book/src/individual/code.dj b/test_djot_book/src/individual/code.dj new file mode 100644 index 0000000000..c1487289d0 --- /dev/null +++ b/test_djot_book/src/individual/code.dj @@ -0,0 +1,33 @@ +# Code + +This section only does simple code blocks and inline code, detailed syntax highlight and stuff is in the languages section + +--- + +``` +This is a codeblock +``` + +--- + +This line contains `inline code` mixed with some other stuff. (LTR) + +ושורה זו מכילה `inline code` אבל עם טקסט בשפה שנכתבת מימין לשמאל. (RTL) + +--- + +```` +escaping ``` in ```, fun, isn't is? +```` + +--- + +```bash,editable +This is an editable codeblock +``` + +--- + +```rust +// This links to a playpen +``` diff --git a/test_djot_book/src/individual/emphasis.dj b/test_djot_book/src/individual/emphasis.dj new file mode 100644 index 0000000000..c16b3d50a7 --- /dev/null +++ b/test_djot_book/src/individual/emphasis.dj @@ -0,0 +1,13 @@ +# Emphasis + +This has *bold text* in between normal. + +This has _italic text_ in between normal. + +A *line* having _both_, bold and italic text. + +*A bold line _having_ italic text* + +_An Italic line having *bold* text_ + +Now this is going *_out of hands_*. diff --git a/test_djot_book/src/individual/heading.dj b/test_djot_book/src/individual/heading.dj new file mode 100644 index 0000000000..f9f4d5b2ea --- /dev/null +++ b/test_djot_book/src/individual/heading.dj @@ -0,0 +1,21 @@ +# Chapter Heading + +--- + +# Really Big Heading + +## Big Heading + +### Normal-ish Heading + +#### Small Heading...? + +##### Really Small Heading + +###### Is it even a heading anymore - heading + +## Custom id {#example-id} + +## Custom class {.class1 .class2} + +## Both id and class {#example-id2 .class1 .class2} diff --git a/test_djot_book/src/individual/image.dj b/test_djot_book/src/individual/image.dj new file mode 100644 index 0000000000..8bb66d3346 --- /dev/null +++ b/test_djot_book/src/individual/image.dj @@ -0,0 +1,27 @@ +# Images + +For copyright and trademark information on these images, please check [rust-artwork repository](https://github.com/rust-lang/rust-artworkhttps://github.com/rust-lang/rust-artwork) + +## A 16x16 image + +![16x16 rust-lang logo](https://rust-lang.org/logos/rust-logo-16x16.png) + +## A 32x32 image + +![32x32 rust-lang logo](https://rust-lang.org/logos/rust-logo-32x32-blk.png) + +## A 256x256 image + +![256x256 rust-lang logo](https://rust-lang.org/logos/rust-logo-256x256.png) + +## A 512x512 image + +![512x512 rust-lang logo](https://rust-lang.org/logos/rust-logo-512x512-blk.png) + +## A large image + +![2018 rust-conf art](https://raw.githubusercontent.com/rust-lang/rust-artwork/master/2018-RustConf/lucy-mountain-climber.png) + +## A SVG image + +![2018 rust-conf art svg](https://raw.githubusercontent.com/rust-lang/rust-artwork/461afe27d8e02451cf9f46e507f2c2a71d2b276b/2018-RustConf/lucy-mountain-climber.svg) diff --git a/test_djot_book/src/individual/linebreak.dj b/test_djot_book/src/individual/linebreak.dj new file mode 100644 index 0000000000..fa78cea613 --- /dev/null +++ b/test_djot_book/src/individual/linebreak.dj @@ -0,0 +1,8 @@ +# Line breaks + +This is a long\ +line with a couple of\ +line breaks in\ +between : both with two\ +spaces and return,\ +and with HTML tags. diff --git a/test_djot_book/src/individual/link_hr.dj b/test_djot_book/src/individual/link_hr.dj new file mode 100644 index 0000000000..7d6b85043a --- /dev/null +++ b/test_djot_book/src/individual/link_hr.dj @@ -0,0 +1,16 @@ +# Links and Horizontal Rule + +This is followed by a Horizontal rule + +--- + +And this is preceded by a horizontal rule. + +[This](www.rust-lang.org) should link to rust-lang website\ +[So should this][rl]{title=this_is_also_djot_specific}.\ +*[This][rl]* is a strong link. +_[This][rl]_ is italic. +*_[This][rl]_* is both. + +{title=this_is_djot_specific} +[rl]: www.rust-lang.org diff --git a/test_djot_book/src/individual/list.dj b/test_djot_book/src/individual/list.dj new file mode 100644 index 0000000000..9377cd1181 --- /dev/null +++ b/test_djot_book/src/individual/list.dj @@ -0,0 +1,89 @@ +# Lists + +## ordered, decimal enumerated, followed by a period + +1. A +2. Normal +3. Ordered +4. List + +## ordered, decimal enumerated, followed by a parenthesis + +1) A + + 1) Nested + 2) List + +2) But +3) Still +4) Normal + +## bullet, minus + +- An +- Unordered +- Normal +- List + +## bullet, plus + ++ Nested + + + Unordered + ++ List + +## bullet, star + +* This + + 1. Is + 2. Normal + +* ?! + +## task + +- [ ] task + +## Djot Specific + +(1) ordered, decimal-enumerated, enclosed in parentheses + +a. ordered, lower-alpha-enumerated, followed by period + +a) ordered, lower-alpha-enumerated, followed by parenthesis + +(a) ordered, lower-alpha-enumerated, enclosed in parentheses + +A. ordered, upper-alpha-enumerated, followed by period + +A) ordered, upper-alpha-enumerated, followed by parenthesis + +(A) ordered, upper-alpha-enumerated, enclosed in parentheses + +i. ordered, lower-roman-enumerated, followed by period + +i) ordered, lower-roman-enumerated, followed by parenthesis + +(i) ordered, lower-roman-enumerated, enclosed in parentheses + +I. ordered, upper-roman-enumerated, followed by period + +I) ordered, upper-roman-enumerated, followed by parenthesis + +(I) ordered, upper-roman-enumerated, enclosed in parentheses + +: term + + definition + +- tight +- tight + ++ loose + ++ loose + +9. starting a list after the number one +22. this is prefixed with the number 22 diff --git a/test_djot_book/src/individual/mathjax.dj b/test_djot_book/src/individual/mathjax.dj new file mode 100644 index 0000000000..693bdf506d --- /dev/null +++ b/test_djot_book/src/individual/mathjax.dj @@ -0,0 +1,41 @@ +# MathJax + +Fourier Transform + +$$` +\begin{aligned} +f(x) &= \int_{-\infty}^{\infty}F(s)(-1)^{ 2xs}ds \\\\ +F(s) &= \int_{-\infty}^{\infty}f(x)(-1)^{-2xs}dx +\end{aligned} +` + +The kernel can also be written as \\(e^{2i\pi xs}\\) which is more frequently used in literature. + +> Proof that $`e^{ix} = \cos x + i\sin x` a.k.a Euler's Formula: +> +> $$` +\begin{aligned} + e^x &= \sum_{n=0}^\infty \frac{x^n}{n!} \implies e^{ix} = \sum_{n=0}^\infty \frac{(ix)^n}{n!} \\\\ + \cos x &= \sum_{m=0}^\infty \frac{(-1)^m x^{2m}}{(2m)!} = \sum_{m=0}^\infty \frac{(ix)^{2m}}{(2m)!} \\\\ + \sin x &= \sum_{s=0}^\infty \frac{(-1)^s x^{2s+1}}{(2s+1)!} = \sum_{s=0}^\infty \frac{(ix)^{2s+1}}{i(2s+1)!} \\\\ + \cos x + i\sin x &= \sum_{l=0}^\infty \frac{(ix)^{2l}}{(2l)!} + \sum_{s=0}^\infty \frac{(ix)^{2s+1}}{(2s+1)!} = \sum_{n=0}^\infty \frac{(ix)^{n}}{n!} \\\\ + &= e^{ix} +\end{aligned} +` +> + +Pauli Matrices + +$$` +\begin{aligned} + \sigma_x &= \begin{pmatrix} + 1 & 0 \\\\ 0 & 1 + \end{pmatrix} \\\\ + \sigma_y &= \begin{pmatrix} + 0 & -i \\\\ i & 0 + \end{pmatrix} \\\\ + \sigma_z &= \begin{pmatrix} + 1 & 0 \\\\ 0 & -1 + \end{pmatrix} +\end{aligned} +` diff --git a/test_djot_book/src/individual/mixed.dj b/test_djot_book/src/individual/mixed.dj new file mode 100644 index 0000000000..ab6cb296e8 --- /dev/null +++ b/test_djot_book/src/individual/mixed.dj @@ -0,0 +1,65 @@ +# Mixed + +This contains all tags randomly mixed together, to make sure style changes in one does not affect others. + +### A heading + +*Quite a Strong statement , to make* + +{-No, cross that-} + +> Whose *quote* is this +> +> > And {-this-} +> > +> > > - and +> > > - this +> > > - also + +``` +You encountered a wild codepen +``` + +```rust,editable +// The codepen is editable and runnable +fn main(){ + println!("Hello world!"); +} +``` + +Ctrl + S saves a file. + +A random image sprinkled in between + +![16x16 rust-lang logo](https://rust-lang.org/logos/rust-logo-16x16.png) + +--- + +- {-An unordered list-} +- *Hello* +- _World_ +- What + + 1. Should + 2. be + 3. `put` + 4. here? + 5. *Ctrl + S saves a file.* + +| col1 | col2 | col 3 | col 4 | col 5 | col 6 | +| ---- | ---- | ----- | ----- | ----- | ----- | +| val1 | val2 | val3 | val5 | val4 | val6 | + +| col1 | col2 | col 3 | An Questionable table header | col 5 | col 6 | +| ---- | ---- | ----- | ---------------------------- | ----- | ---------------------------------------- | +| val1 | val2 | val3 | val5 | val4 | An equally Questionable long table value | + +### Things to do + +- [x] Add individual tags +- [ ] Add language examples +- [ ] Add rust specific examples + +And another image + +![2018 rust-conf art svg](https://raw.githubusercontent.com/rust-lang/rust-artwork/461afe27d8e02451cf9f46e507f2c2a71d2b276b/2018-RustConf/lucy-mountain-climber.svg) diff --git a/test_djot_book/src/individual/paragraph.dj b/test_djot_book/src/individual/paragraph.dj new file mode 100644 index 0000000000..032dd6eac3 --- /dev/null +++ b/test_djot_book/src/individual/paragraph.dj @@ -0,0 +1,25 @@ +Just a simple paragraph. + +Let's stress test this. + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer elit lorem, eleifend eu leo sit amet, suscipit feugiat libero. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Proin congue lectus sit amet lacus venenatis, ac sollicitudin purus condimentum. Suspendisse pretium volutpat sapien at gravida. In tincidunt, sem non accumsan consectetur, leo libero porttitor dolor, at imperdiet erat nibh quis leo. Cras dictum erat augue, quis pharetra justo porttitor posuere. Aenean sed lacinia justo, vel suscipit nisl. Etiam eleifend id mauris at gravida. Aliquam molestie cursus lorem pulvinar sollicitudin. Nam et ex dignissim, posuere sem non, pellentesque lacus. Morbi vulputate sed lorem et convallis. Duis non turpis eget elit posuere volutpat. Donec accumsan euismod enim, id consequat ex rhoncus ac. Pellentesque ac felis nisl. Duis imperdiet vel tellus ac iaculis. + +Vivamus nec tempus enim. Integer in ligula eget elit ornare vulputate id et est. Proin mi elit, sagittis nec urna et, iaculis imperdiet neque. Vestibulum placerat cursus dolor. Donec eu sodales nulla. Praesent ac tellus eros. Donec venenatis ligula id ex porttitor malesuada. Aliquam maximus, nisi in fringilla finibus, ante elit rhoncus dui, placerat semper nisl tellus quis odio. Cras luctus magna ultrices dolor pharetra volutpat. Maecenas non enim vitae ligula efficitur aliquet id quis quam. In sagittis mollis magna eu porta. Morbi at nulla et ante elementum pharetra in sed est. Nam commodo purus enim. + +Ut non elit sit amet urna luctus facilisis vel et sapien. Morbi nec metus at libero imperdiet sollicitudin eget quis lacus. Donec in ipsum at enim accumsan tempor vel sed magna. Aliquam non imperdiet neque. Etiam pharetra neque sed pretium interdum. Suspendisse potenti. Phasellus varius, lectus quis dapibus faucibus, purus mauris accumsan nibh, vel tempor quam metus nec sem. Nunc sagittis suscipit lorem eu finibus. Nullam augue leo, imperdiet vel diam et, vulputate scelerisque turpis. Nullam ut volutpat diam. Praesent cursus accumsan dui a commodo. Vivamus sed libero sed turpis facilisis rutrum id sed ligula. Ut id sollicitudin dui. Nulla pulvinar commodo lectus. Cras ut quam congue, consectetur dolor ac, consequat ante. + +Curabitur scelerisque sed leo eu facilisis. Nam faucibus neque eget dictum hendrerit. Duis efficitur ex sed vulputate volutpat. Praesent condimentum nisl ac sapien efficitur laoreet. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut ut nibh elit. Nunc a neque lobortis, tempus diam vitae, interdum magna. Aenean eget nisl sed justo volutpat interdum. Mauris malesuada ex nisl, a dignissim dui elementum eget. Suspendisse potenti. + +Praesent congue fringilla sem sed faucibus. Vivamus malesuada eget mauris at molestie. In sed faucibus nulla. Vivamus elementum accumsan metus quis suscipit. Maecenas interdum est nulla. Cras volutpat cursus nibh quis sollicitudin. Morbi vitae massa laoreet, aliquet tellus quis, consectetur ipsum. Mauris euismod congue purus non condimentum. Etiam laoreet mi vel sem consectetur gravida. Vestibulum volutpat magna nunc, vitae ultrices risus commodo eu. + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer elit lorem, eleifend eu leo sit amet, suscipit feugiat libero. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Proin congue lectus sit amet lacus venenatis, ac sollicitudin purus condimentum. Suspendisse pretium volutpat sapien at gravida. In tincidunt, sem non accumsan consectetur, leo libero porttitor dolor, at imperdiet erat nibh quis leo. Cras dictum erat augue, quis pharetra justo porttitor posuere. Aenean sed lacinia justo, vel suscipit nisl. Etiam eleifend id mauris at gravida. Aliquam molestie cursus lorem pulvinar sollicitudin. Nam et ex dignissim, posuere sem non, pellentesque lacus. Morbi vulputate sed lorem et convallis. Duis non turpis eget elit posuere volutpat. Donec accumsan euismod enim, id consequat ex rhoncus ac. Pellentesque ac felis nisl. Duis imperdiet vel tellus ac iaculis. + +Vivamus nec tempus enim. Integer in ligula eget elit ornare vulputate id et est. Proin mi elit, sagittis nec urna et, iaculis imperdiet neque. Vestibulum placerat cursus dolor. Donec eu sodales nulla. Praesent ac tellus eros. Donec venenatis ligula id ex porttitor malesuada. Aliquam maximus, nisi in fringilla finibus, ante elit rhoncus dui, placerat semper nisl tellus quis odio. Cras luctus magna ultrices dolor pharetra volutpat. Maecenas non enim vitae ligula efficitur aliquet id quis quam. In sagittis mollis magna eu porta. Morbi at nulla et ante elementum pharetra in sed est. Nam commodo purus enim. + +Ut non elit sit amet urna luctus facilisis vel et sapien. Morbi nec metus at libero imperdiet sollicitudin eget quis lacus. Donec in ipsum at enim accumsan tempor vel sed magna. Aliquam non imperdiet neque. Etiam pharetra neque sed pretium interdum. Suspendisse potenti. Phasellus varius, lectus quis dapibus faucibus, purus mauris accumsan nibh, vel tempor quam metus nec sem. Nunc sagittis suscipit lorem eu finibus. Nullam augue leo, imperdiet vel diam et, vulputate scelerisque turpis. Nullam ut volutpat diam. Praesent cursus accumsan dui a commodo. Vivamus sed libero sed turpis facilisis rutrum id sed ligula. Ut id sollicitudin dui. Nulla pulvinar commodo lectus. Cras ut quam congue, consectetur dolor ac, consequat ante. + +Curabitur scelerisque sed leo eu facilisis. Nam faucibus neque eget dictum hendrerit. Duis efficitur ex sed vulputate volutpat. Praesent condimentum nisl ac sapien efficitur laoreet. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut ut nibh elit. Nunc a neque lobortis, tempus diam vitae, interdum magna. Aenean eget nisl sed justo volutpat interdum. Mauris malesuada ex nisl, a dignissim dui elementum eget. Suspendisse potenti. + +Praesent congue fringilla sem sed faucibus. Vivamus malesuada eget mauris at molestie. In sed faucibus nulla. Vivamus elementum accumsan metus quis suscipit. Maecenas interdum est nulla. Cras volutpat cursus nibh quis sollicitudin. Morbi vitae massa laoreet, aliquet tellus quis, consectetur ipsum. Mauris euismod congue purus non condimentum. Etiam laoreet mi vel sem consectetur gravida. Vestibulum volutpat magna nunc, vitae ultrices risus commodo eu. + +Hopefully everything above was rendered nicely, on both desktop and mobile. diff --git a/test_djot_book/src/individual/strikethrough.dj b/test_djot_book/src/individual/strikethrough.dj new file mode 100644 index 0000000000..e171dc6da4 --- /dev/null +++ b/test_djot_book/src/individual/strikethrough.dj @@ -0,0 +1,7 @@ +# Strikethrough + +{-Single strike-} + +{-This is Striked-} + +{-This is *strong*, _italic_ , *_both_* and striked-} diff --git a/test_djot_book/src/individual/table.dj b/test_djot_book/src/individual/table.dj new file mode 100644 index 0000000000..0afb5faa0f --- /dev/null +++ b/test_djot_book/src/individual/table.dj @@ -0,0 +1,33 @@ +# Tables + +| col1 | col2 | +| ---- | ---- | + +--- + +djot specific alignment and caption + +| col1 | col2 | col 3 | col 4 | +|:-------------- | -------------:|:--------------:| --------------- | +| left aligned | right aligned | center aligned | default aligned | +| X | X | X | X | + +^ a caption + +--- + +| col1 | col2 | col 3 | col 4 | col 5 | col 6 | +| ---- | ---- | ----- | ----- | ----- | ----- | +| val1 | val2 | val3 | val5 | val4 | val6 | +| val1 | val2 | val3 | val5 | val4 | val6 | +| val1 | val2 | val3 | val5 | val4 | val6 | +| val1 | val2 | val3 | val5 | val4 | val6 | + +--- + +| col1 | col2 | col 3 | col 4 | col 5 | col 6 | +| -------------------------------------------------------------------------------------------------------------- | ---- | -------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ----- | -------------------------------------------------------------------------------------------------------------- | +| This is a simple demo book, which is intended to be used for verifying and validating style changes in mdBook. | val2 | val3 | val5 | val4 | val6 | +| val1 | val2 | val3 | val5 | val4 | val6 | +| val1 | val2 | val3 | val5 | val4 | This is a simple demo book, which is intended to be used for verifying and validating style changes in mdBook. | +| val1 | val2 | This is a simple demo book, which is intended to be used for verifying and validating style changes in mdBook. | This is a simple demo book, which is intended to be used for verifying and validating style changes in mdBook. | val4 | val6 | diff --git a/test_djot_book/src/individual/task.dj b/test_djot_book/src/individual/task.dj new file mode 100644 index 0000000000..2be6f2bbe3 --- /dev/null +++ b/test_djot_book/src/individual/task.dj @@ -0,0 +1,11 @@ +# Tasks + +- [ ] Task 1 +- [ ] Task 2 +- [x] Completed Task 1 +- [x] Completed Task 2 + +--- + +- [ ] *Important Task* +- [x] _Completed Important task_ diff --git a/test_djot_book/src/individual/thematic_break.dj b/test_djot_book/src/individual/thematic_break.dj new file mode 100644 index 0000000000..66eb633840 --- /dev/null +++ b/test_djot_book/src/individual/thematic_break.dj @@ -0,0 +1,17 @@ +# Thematic Break + +3 dashses + +--- + +a long line of dashes + +--------------- + +3 stars + +*** + +a long line of stars + +*********** diff --git a/test_djot_book/src/languages/README.dj b/test_djot_book/src/languages/README.dj new file mode 100644 index 0000000000..32c293f538 --- /dev/null +++ b/test_djot_book/src/languages/README.dj @@ -0,0 +1,49 @@ +# Syntax Highlighting + +This Currently contains following languages + +- apache +- armasm +- bash +- c +- coffeescript +- cpp +- csharp +- css +- d +- diff +- go +- handlebars +- haskell +- http +- ini +- java +- javascript +- json +- julia +- kotlin +- less +- lua +- makefile +- markdown +- nginx +- nim +- nix +- objectivec +- perl +- php +- plaintext +- properties +- python +- r +- ruby +- rust +- scala +- scss +- shell +- sql +- swift +- typescript +- x86asm +- xml +- yaml diff --git a/test_djot_book/src/languages/highlight.dj b/test_djot_book/src/languages/highlight.dj new file mode 100644 index 0000000000..6f3d19ca91 --- /dev/null +++ b/test_djot_book/src/languages/highlight.dj @@ -0,0 +1,956 @@ +# Syntax Highlights + +## apache + +```apache +# rewrite`s rules for wordpress pretty url +LoadModule rewrite_module modules/mod_rewrite.so +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule . index.php [NC,L] + +ExpiresActive On +ExpiresByType application/x-javascript "access plus 1 days" + +Order Deny,Allow +Allow from All + + + RewriteMap map txt:map.txt + RewriteMap lower int:tolower + RewriteCond %{REQUEST_URI} ^/([^/.]+)\.html$ [NC] + RewriteCond ${map:${lower:%1}|NOT_FOUND} !NOT_FOUND + RewriteRule .? /index.php?q=${map:${lower:%1}} [NC,L] + + +20.164.151.111 - - [20/Aug/2015:22:20:18 -0400] "GET /mywebpage/index.php HTTP/1.1" 403 772 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1" +``` + +## armasm + +```armasm +.data + +/* Data segment: define our message string and calculate its length. */ +msg: + .ascii "Hello, ARM!\n" +len = . - msg + +.text + +/* Our application's entry point. */ +.globl _start +_start: + /* syscall write(int fd, const void *buf, size_t count) */ + mov %r0, $1 /* fd := STDOUT_FILENO */ + ldr %r1, =msg /* buf := msg */ + ldr %r2, =len /* count := len */ + mov %r7, $4 /* write is syscall #4 */ + swi $0 /* invoke syscall */ + + /* syscall exit(int status) */ + mov %r0, $0 /* status := 0 */ + mov %r7, $1 /* exit is syscall #1 */ + swi $0 /* invoke syscall */ + +``` + +## bash + +```bash +#!/bin/bash + +###### CONFIG +ACCEPTED_HOSTS="/root/.hag_accepted.conf" +BE_VERBOSE=false + +if [ "$UID" -ne 0 ] +then + echo "Superuser rights required" + exit 2 +fi + +genApacheConf(){ + echo -e "# Host ${HOME_DIR}$1/$2 :" +} + +echo '"quoted"' | tr -d \" > text.txt + +``` + +## c + +```c +#include +void main(int argc,char ** argv){ + printf("Hello World!"); +} + +``` + +## coffeescript + +```coffeescript +grade = (student, period=(if b? then 7 else 6)) -> + if student.excellentWork + "A+" + else if student.okayStuff + if student.triedHard then "B" else "B-" + else + "C" + +class Animal extends Being + constructor: (@name) -> + + move: (meters) -> + alert @name + " moved #{meters}m." +``` + +## cpp + +```cpp +#include +using namespace std; +int main() { + cout << "Hello, World!" << endl; // This prints Hello, World! + return 0; +} +``` + +## csharp + +```csharp +using System; +class App +{ + static void Main() + { + Console.WriteLine("Hello World!"); + } +} +``` + +## css + +```css +@font-face { + font-family: Chunkfive; + src: url('Chunkfive.otf'); +} + +body, +.usertext { + color: #f0f0f0; + background: #600; + font-family: Chunkfive, sans; + --heading-1: 30px/32px Helvetica, sans-serif; +} + +@import url(print.css); +@media print { + a[href^='http']::after { + content: attr(href); + } +} +``` + +## d + +```d +/* This program prints a + hello world message + to the console. */ + +import std.stdio; + +void main() +{ + writeln("Hello, World!"); +} +``` + +## diff + +```diff +Index: languages/ini.js +=================================================================== +--- languages/ini.js (revision 199) ++++ languages/ini.js (revision 200) +@@ -1,8 +1,7 @@ + hljs.LANGUAGES.ini = + { + case_insensitive: true, +- defaultMode: +- { ++ defaultMode: { + contains: ['comment', 'title', 'setting'], + illegal: '[^\\s]' + }, + +*** /path/to/original timestamp +--- /path/to/new timestamp +*************** +*** 1,3 **** +--- 1,9 ---- ++ This is an important ++ notice! It should ++ therefore be located at ++ the beginning of this ++ document! + +! compress the size of the +! changes. + + It is important to spell +``` + +## go + +```go +package main +import "fmt" + +func main() { + fmt.Println("Hello World!") +} +``` + +## handlebars + +```handlebars +
+ {{! only show if author exists }} + {{#if author}} +

{{firstName}} {{lastName}}

+ {{/if}} +
+``` + +## haskell + +```haskell +main :: IO () +main = putStrLn "Hello World!" + +``` + +## http + +```http +POST /task?id=1 HTTP/1.1 +Host: example.org +Content-Type: application/json; charset=utf-8 +Content-Length: 137 + +{ + "status": "ok", + "extended": true, + "results": [ + {"value": 0, "type": "int64"}, + {"value": 1.0e+3, "type": "decimal"} + ] +} + +``` + +## ini + +```ini +; boilerplate +[package] +name = "some_name" +authors = ["Author"] +description = "This is \ +a description" + +[[lib]] +name = ${NAME} +default = True +auto = no +counter = 1_000 +``` + +## java + +```java +class Main { + public static void main(String[] args) { + System.out.println("Hello World!"); + } +} +``` + +## javascript + +```javascript +function $initHighlight(block, cls) { + try { + if (cls.search(/\bno\-highlight\b/) != -1) + return process(block, true, 0x0F) + + ` class="${cls}"`; + } catch (e) { + /* handle exception */ + } + for (var i = 0 / 2; i < classes.length; i++) { + if (checkCondition(classes[i]) === undefined) + console.log('undefined'); + } + + return ( +
+ {block} +
+ ) +} + +export $initHighlight; +``` + +## json + +```json +[ + { + "title": "apples", + "count": [12000, 20000], + "description": { "text": "...", "sensitive": false } + }, + { + "title": "oranges", + "count": [17500, null], + "description": { "text": "...", "sensitive": false } + } +] +``` + +## julia + +```julia +# function to calculate the volume of a sphere +function sphere_vol(r) + # julia allows Unicode names (in UTF-8 encoding) + # so either "pi" or the symbol π can be used + return 4/3*pi*r^3 +end + +# functions can also be defined more succinctly +quadratic(a, sqr_term, b) = (-b + sqr_term) / 2a + +# calculates x for 0 = a*x^2+b*x+c, arguments types can be defined in function definitions +function quadratic2(a::Float64, b::Float64, c::Float64) + # unlike other languages 2a is equivalent to 2*a + # a^2 is used instead of a**2 or pow(a,2) + sqr_term = sqrt(b^2-4a*c) + r1 = quadratic(a, sqr_term, b) + r2 = quadratic(a, -sqr_term, b) + # multiple values can be returned from a function using tuples + # if the return keyword is omitted, the last term is returned + r1, r2 +end + +vol = sphere_vol(3) +``` + +## kotlin + +```kotlin +package org.kotlinlang.play + +fun main() { + println("Hello, World!") +} +``` + +## less + +```less +@import 'fruits'; + +@rhythm: 1.5em; + +@media screen and (min-resolution: 2dppx) { + body { + font-size: 125%; + } +} + +section > .foo + #bar:hover [href*='less'] { + margin: @rhythm 0 0 @rhythm; + padding: calc(5% + 20px); + background: #f00ba7 url(http://placehold.alpha-centauri/42.png) no-repeat; + background-image: linear-gradient(-135deg, wheat, fuchsia) !important ; + background-blend-mode: multiply; +} + +@font-face { + font-family: /* ? */ 'Omega'; + src: url('../fonts/omega-webfont.woff?v=2.0.2'); +} + +.icon-baz::before { + display: inline-block; + font-family: 'Omega', Alpha, sans-serif; + content: '\f085'; + color: rgba(98, 76 /* or 54 */, 231, 0.75); +} +``` + +## lua + +```lua +--[[ +Simple signal/slot implementation +]] +local signal_mt = { + __index = { + register = table.insert + } +} +function signal_mt.__index:emit(... --[[ Comment in params ]]) + for _, slot in ipairs(self) do + slot(self, ...) + end +end +local function create_signal() + return setmetatable({}, signal_mt) +end + +-- Signal test +local signal = create_signal() +signal:register(function(signal, ...) + print(...) +end) +signal:emit('Answer to Life, the Universe, and Everything:', 42) + +--[==[ [=[ [[ +Nested ]] +multi-line ]=] +comment ]==] +[==[ Nested +[=[ multi-line +[[ string +]] ]=] ]==] +``` + +## makefile + +```makefile +# Makefile + +BUILDDIR = _build +EXTRAS ?= $(BUILDDIR)/extras + +.PHONY: main clean + +main: + @echo "Building main facility..." + build_main $(BUILDDIR) + +clean: + rm -rf $(BUILDDIR)/* + +``` + +## markdown + +```markdown +# hello world + +you can write text [with links](http://example.com) inline or [link references][1]. + +- one _thing_ has *em*phasis +- two **things** are **bold** + +[1]: http://example.com + +--- + +# hello world + + + +> markdown is so cool + + so are code segments + +1. one thing (yeah!) +2. two thing `i can write code`, and `more` wipee! +``` + +## nginx + +```nginx +user www www; +worker_processes 2; +pid /var/run/nginx.pid; +error_log /var/log/nginx.error_log debug | info | notice | warn | error | crit; + +events { + connections 2000; + use kqueue | rtsig | epoll | /dev/poll | select | poll; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $bytes_sent ' + '"$http_referer" "$http_user_agent" ' + '"$gzip_ratio"'; + + send_timeout 3m; + client_header_buffer_size 1k; + + gzip on; + gzip_min_length 1100; + + #lingering_time 30; + + server { + server_name one.example.com www.one.example.com; + access_log /var/log/nginx.access_log main; + + rewrite (.*) /index.php?page=$1 break; + + location / { + proxy_pass http://127.0.0.1/; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + charset koi8-r; + } + + location /api/ { + fastcgi_pass 127.0.0.1:9000; + } + + location ~* \.(jpg|jpeg|gif)$ { + root /spool/www; + } + } +} +``` + +## nim + +```nim +from strutils import `%` + +const numDoors = 100 +var doors {.compileTime.}: array[1..numDoors, bool] + +proc calcDoors(): string = + for pass in 1..numDoors: + for door in countup(pass, numDoors, pass): + doors[door] = not doors[door] + for door in 1..numDoors: + result.add("Door $1 is $2.\n" % [$door, if doors[door]: "open" else: "closed"]) + +const outputString: string = calcDoors() + +echo outputString +``` + +## objectivec + +```objectivec +#import + +int main(int argc, const char * argv[]) { + @mylak { + NSLog(@"Hello World!"); + } + return 0; +} + +``` + +## nix + +```nix +let + world = "World!"; +in +"Hello " + world +``` + +## perl + +```perl +print "Hello World!\n"; +``` + +## php + +```php + +``` + +## plaintext + +```plaintext +I think this is simply plain text? +Hello World! +``` + +## properties + +```properties +# .properties +! Exclamation mark = comments, too + +key1 = value1 +key2 : value2 +key3 value3 +key\ spaces multiline\ + value4 +empty_key +! Key can contain escaped chars +\:\= = value5 +``` + +## python + +```python +@requires_authorization(roles=["ADMIN"]) +def somefunc(param1='', param2=0): + r'''A docstring''' + if param1 > param2: # interesting + print 'Gre\'ater' + return (param2 - param1 + 1 + 0b10l) or None + +class SomeClass: + pass + +>>> message = '''interpreter +... prompt''' +``` + +## r + +```r +require(stats) + +#' Compute different averages +#' +#' @param x \code{numeric} vector of sample data +#' @param type \code{character} vector of length 1 specifying the average type +#' @return \code{centre} returns the sample average according to the chosen method. +#' @examples +#' centre(rcauchy(10), "mean") +#' @export +centre <- function(x, type) { + switch(type, + mean = mean(x), + median = median(x), + trimmed = mean(x, trim = .1)) +} +x <- rcauchy(10) +centre(x, "mean") + +library(ggplot2) + +models <- tibble::tribble( + ~model_name, ~ formula, + "length-width", Sepal.Length ~ Petal.Width + Petal.Length, + "interaction", Sepal.Length ~ Petal.Width * Petal.Length +) + +iris %>% + nest_by(Species) %>% + left_join(models, by = character()) %>% + rowwise(Species, model_name) %>% + mutate(model = list(lm(formula, data = data))) %>% + summarise(broom::glance(model)) +``` + +## ruby + +```ruby +# The Greeter class +class Greeter + def initialize(name) + @name = name.capitalize + end + + def salute + puts "Hello #{@name}!" + end +end + +g = Greeter.new("world") +g.salute +``` + +## rust + +```rust +fn main()->(){ + println!("Hello World!"); +} +``` + +## scala + +```scala +/** + * A person has a name and an age. + */ +case class Person(name: String, age: Int) + +abstract class Vertical extends CaseJeu +case class Haut(a: Int) extends Vertical +case class Bas(name: String, b: Double) extends Vertical + +sealed trait Ior[+A, +B] +case class Left[A](a: A) extends Ior[A, Nothing] +case class Right[B](b: B) extends Ior[Nothing, B] +case class Both[A, B](a: A, b: B) extends Ior[A, B] + +trait Functor[F[_]] { + def map[A, B](fa: F[A], f: A => B): F[B] +} + +// beware Int.MinValue +def absoluteValue(n: Int): Int = + if (n < 0) -n else n + +def interp(n: Int): String = + s"there are $n ${color} balloons.\n" + +type ξ[A] = (A, A) + +trait Hist { lhs => + def ⊕(rhs: Hist): Hist +} + +def gsum[A: Ring](as: Seq[A]): A = + as.foldLeft(Ring[A].zero)(_ + _) + +val actions: List[Symbol] = + 'init :: 'read :: 'write :: 'close :: Nil +``` + +## scss + +```scss +import "compass/reset"; + +// variables +$colorGreen: #008000; +$colorGreenDark: darken($colorGreen, 10); + +@mixin container { + max-width: 980px; +} + +// mixins with parameters +@mixin button($color:green) { + @if ($color == green) { + background-color: #008000; + } + @else if ($color == red) { + background-color: #B22222; + } +} + +button { + @include button(red); +} + +div, +.navbar, +#header, +input[type="input"] { + font-family: "Helvetica Neue", Arial, sans-serif; + width: auto; + margin: 0 auto; + display: block; +} + +.row-12 > [class*="spans"] { + border-left: 1px solid #B5C583; +} + +``` + +## shell + +```shell +$ echo $EDITOR +vim +$ git checkout main +Switched to branch 'main' +Your branch is up-to-date with 'origin/main'. +$ git push +Everything up-to-date +$ echo 'All +> done!' +All +done! + +``` + +## sql + +```sql +CREATE TABLE "topic" ( + "id" integer NOT NULL PRIMARY KEY, + "forum_id" integer NOT NULL, + "subject" varchar(255) NOT NULL +); +ALTER TABLE "topic" +ADD CONSTRAINT forum_id FOREIGN KEY ("forum_id") +REFERENCES "forum" ("id"); + +-- Initials +insert into "topic" ("forum_id", "subject") +values (2, 'D''artagnian'); +``` + +## swift + +```swift +import Foundation + +@objc class Person: Entity { + var name: String! + var age: Int! + + init(name: String, age: Int) { + /* /* ... */ */ + } + + // Return a descriptive string for this person + func description(offset: Int = 0) -> String { + return "\(name) is \(age + offset) years old" + } +} +``` + +## typescript + +```typescript +class MyClass { + public static myValue: string; + constructor(init: string) { + this.myValue = init; + } +} +import fs = require("fs"); +module MyModule { + export interface MyInterface extends Other { + myProperty: any; + } +} +declare magicNumber number; +myArray.forEach(() => { }); // fat arrow syntax + +``` + +## x86asm + +```x86asm +section .text +extern _MessageBoxA@16 +%if __NASM_VERSION_ID__ >= 0x02030000 +safeseh handler ; register handler as "safe handler" +%endif + +handler: + push dword 1 ; MB_OKCANCEL + push dword caption + push dword text + push dword 0 + call _MessageBoxA@16 + sub eax,1 ; incidentally suits as return value + ; for exception handler + ret + +global _main +_main: push dword handler + push dword [fs:0] + mov dword [fs:0], esp + xor eax,eax + mov eax, dword[eax] ; cause exception + pop dword [fs:0] ; disengage exception handler + add esp, 4 + ret + +avx2: vzeroupper + push rbx + mov rbx, rsp + sub rsp, 0h20 + vmovdqa ymm0, [rcx] + vpaddb ymm0, [rdx] + leave + ret + +text: db 'OK to rethrow, CANCEL to generate core dump',0 +caption:db 'SEGV',0 + +section .drectve info + db '/defaultlib:user32.lib /defaultlib:msvcrt.lib ' +``` + +## xml + +```xml + +Title + + + + + + +

Title

+ + +``` + +## yaml + +```yaml +--- +# comment +string_1: "Bar" +string_2: 'bar' +string_3: bar +inline_keys_ignored: sompath/name/file.jpg +keywords_in_yaml: + - true + - false + - TRUE + - FALSE + - 21 + - 21.0 + - !!str 123 +"quoted_key": &foobar + bar: foo + foo: + "foo": bar + +reference: *foobar + +multiline_1: | + Multiline + String +multiline_2: > + Multiline + String +multiline_3: " + Multiline string + " + +ansible_variables: "foo {{variable}}" + +array_nested: +- a +- b: 1 + c: 2 +- b +- comment +``` diff --git a/test_djot_book/src/prefix.dj b/test_djot_book/src/prefix.dj new file mode 100644 index 0000000000..1c40c2cb4b --- /dev/null +++ b/test_djot_book/src/prefix.dj @@ -0,0 +1,3 @@ +# Prefix Chapter + +This is to verify the placement and style of prefix chapter in book index. diff --git a/test_djot_book/src/rust/README.dj b/test_djot_book/src/rust/README.dj new file mode 100644 index 0000000000..e3bb350f0f --- /dev/null +++ b/test_djot_book/src/rust/README.dj @@ -0,0 +1 @@ +# Rust specific code examples diff --git a/test_djot_book/src/rust/rust_codeblock.dj b/test_djot_book/src/rust/rust_codeblock.dj new file mode 100644 index 0000000000..5fb2b72496 --- /dev/null +++ b/test_djot_book/src/rust/rust_codeblock.dj @@ -0,0 +1,27 @@ +## Rust codeblocks + +This contains various examples of codeblocks, specific to rust + +## Simple + +```rust +fn main(){ + println!("Hello world!"); +} +``` + +## With Hidden lines + +```rust +# fn main(){ + println!("Hello world!"); +# } +``` + +## Editable + +```rust,editable +fn main(){ + println!("Hello world!"); +} +``` diff --git a/test_djot_book/src/suffix.dj b/test_djot_book/src/suffix.dj new file mode 100644 index 0000000000..9d86853cfd --- /dev/null +++ b/test_djot_book/src/suffix.dj @@ -0,0 +1,3 @@ +# Suffix Chapter + +This is to verify the placement and style of suffix chapter in book index.