mirror of https://github.com/rust-lang/book
Removed copyright notices & made cosmetic improvements.
This commit is contained in:
parent
c4795c3358
commit
d1b71d1c8e
|
@ -1,13 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
# file at the top-level directory of this distribution and at
|
|
||||||
# http://rust-lang.org/COPYRIGHT.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
# option. This file may not be copied, modified, or distributed
|
|
||||||
# except according to those terms.
|
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
# file at the top-level directory of this distribution and at
|
|
||||||
# http://rust-lang.org/COPYRIGHT.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
# option. This file may not be copied, modified, or distributed
|
|
||||||
# except according to those terms.
|
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
@ -16,18 +7,18 @@ cargo build --release
|
||||||
mkdir -p tmp
|
mkdir -p tmp
|
||||||
rm -rf tmp/*.md
|
rm -rf tmp/*.md
|
||||||
|
|
||||||
# Get all the markdown files in the src dir,
|
# Get all the Markdown files in the src dir,
|
||||||
ls src/${1:-""}*.md | \
|
ls src/${1:-""}*.md | \
|
||||||
# except for SUMMARY.md.
|
# except for `SUMMARY.md`.
|
||||||
grep -v SUMMARY.md | \
|
grep -v SUMMARY.md | \
|
||||||
# Extract just the filename so we can reuse it easily.
|
# Extract just the filename so we can reuse it easily.
|
||||||
xargs -n 1 basename | \
|
xargs -n 1 basename | \
|
||||||
# Remove all links followed by <!-- ignore -->, then
|
# Remove all links followed by `<!-- ignore -->``, then
|
||||||
# Change all remaining links from markdown to italicized inline text.
|
# Change all remaining links from Markdown to italicized inline text.
|
||||||
while IFS= read -r filename; do
|
while IFS= read -r filename; do
|
||||||
< "src/$filename" ./target/release/remove_links \
|
< "src/$filename" ./target/release/remove_links \
|
||||||
| ./target/release/link2print \
|
| ./target/release/link2print \
|
||||||
| ./target/release/remove_markup > "tmp/$filename"
|
| ./target/release/remove_markup > "tmp/$filename"
|
||||||
done
|
done
|
||||||
# Concat the files into the nostarch dir.
|
# Concatenate the files into the `nostarch` dir.
|
||||||
./target/release/concat_chapters tmp nostarch
|
./target/release/concat_chapters tmp nostarch
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
#[macro_use] extern crate lazy_static;
|
#[macro_use] extern crate lazy_static;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
@ -22,7 +12,6 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for line in buffer.lines() {
|
for line in buffer.lines() {
|
||||||
|
|
||||||
if line.is_empty() {
|
if line.is_empty() {
|
||||||
is_in_inline_code = false;
|
is_in_inline_code = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,11 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// We have some long regex literals, so:
|
// We have some long regex literals, so:
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
|
|
||||||
extern crate rustc_serialize;
|
|
||||||
extern crate docopt;
|
extern crate docopt;
|
||||||
use docopt::Docopt;
|
extern crate rustc_serialize;
|
||||||
extern crate walkdir;
|
extern crate walkdir;
|
||||||
|
|
||||||
|
use docopt::Docopt;
|
||||||
use std::{path, fs, io};
|
use std::{path, fs, io};
|
||||||
use std::io::{BufRead, Write};
|
use std::io::{BufRead, Write};
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,4 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
// FIXME: we have some long lines that could be refactored, but it's not a big deal.
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
|
|
||||||
// FIXME: We have some long lines that could be refactored, but it's not a big deal.
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
|
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
@ -20,7 +9,6 @@ use std::io::{Read, Write};
|
||||||
use regex::{Regex, Captures};
|
use regex::{Regex, Captures};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
write_md(parse_links(parse_references(read_md())));
|
write_md(parse_links(parse_references(read_md())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +26,7 @@ fn write_md(output: String) {
|
||||||
|
|
||||||
fn parse_references(buffer: String) -> (String, HashMap<String, String>) {
|
fn parse_references(buffer: String) -> (String, HashMap<String, String>) {
|
||||||
let mut ref_map = HashMap::new();
|
let mut ref_map = HashMap::new();
|
||||||
// FIXME: Currently doesn't handle "title" in following line
|
// FIXME: currently doesn't handle "title" in following line.
|
||||||
let re = Regex::new(r###"(?m)\n?^ {0,3}\[([^]]+)\]:[[:blank:]]*(.*)$"###).unwrap();
|
let re = Regex::new(r###"(?m)\n?^ {0,3}\[([^]]+)\]:[[:blank:]]*(.*)$"###).unwrap();
|
||||||
let output = re.replace_all(&buffer, |caps: &Captures| {
|
let output = re.replace_all(&buffer, |caps: &Captures| {
|
||||||
let key = caps.at(1).unwrap().to_owned().to_uppercase();
|
let key = caps.at(1).unwrap().to_owned().to_uppercase();
|
||||||
|
@ -52,7 +40,7 @@ fn parse_references(buffer: String) -> (String, HashMap<String, String>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
||||||
// FIXME: check which punctuation is allowed by spec
|
// FIXME: check which punctuation is allowed by spec.
|
||||||
let re = Regex::new(r###"(?:(?P<pre>(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P<name>[^]]+)\](?:(?:\([[:blank:]]*(?P<val>[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P<key>[^]]*)\]))?))"###).expect("could not create regex");
|
let re = Regex::new(r###"(?:(?P<pre>(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P<name>[^]]+)\](?:(?:\([[:blank:]]*(?P<val>[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P<key>[^]]*)\]))?))"###).expect("could not create regex");
|
||||||
let error_code = Regex::new(r###"^E\d{4}$"###).expect("could not create regex");
|
let error_code = Regex::new(r###"^E\d{4}$"###).expect("could not create regex");
|
||||||
let output = re.replace_all(&buffer, |caps: &Captures| {
|
let output = re.replace_all(&buffer, |caps: &Captures| {
|
||||||
|
@ -62,7 +50,7 @@ fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
||||||
let name = caps.name("name").expect("could not get name").to_owned();
|
let name = caps.name("name").expect("could not get name").to_owned();
|
||||||
// Really we should ignore text inside code blocks,
|
// Really we should ignore text inside code blocks,
|
||||||
// this is a hack to not try to treat `#[derive()]`,
|
// this is a hack to not try to treat `#[derive()]`,
|
||||||
// `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link
|
// `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link.
|
||||||
if name.starts_with("derive(") ||
|
if name.starts_with("derive(") ||
|
||||||
name.starts_with("profile") ||
|
name.starts_with("profile") ||
|
||||||
name.starts_with("test") ||
|
name.starts_with("test") ||
|
||||||
|
@ -71,19 +59,19 @@ fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
let val = match caps.name("val") {
|
let val = match caps.name("val") {
|
||||||
// [name](link)
|
// `[name](link)`
|
||||||
Some(value) => value.to_owned(),
|
Some(value) => value.to_owned(),
|
||||||
None => {
|
None => {
|
||||||
match caps.name("key") {
|
match caps.name("key") {
|
||||||
Some(key) => {
|
Some(key) => {
|
||||||
match key {
|
match key {
|
||||||
// [name][]
|
// `[name][]`
|
||||||
"" => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
|
"" => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
|
||||||
// [name][reference]
|
// `[name][reference]`
|
||||||
_ => format!("{}", ref_map.get(&key.to_uppercase()).expect(&format!("could not find url for the link text `{}`", key))),
|
_ => format!("{}", ref_map.get(&key.to_uppercase()).expect(&format!("could not find url for the link text `{}`", key))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// [name] as reference
|
// `[name]` as reference
|
||||||
None => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
|
None => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,7 +403,4 @@ Some text to show that the reference links can follow later.
|
||||||
.to_string();
|
.to_string();
|
||||||
assert_eq!(parse(source), target);
|
assert_eq!(parse(source), target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,9 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use regex::{Regex, Captures};
|
use regex::{Regex, Captures};
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
fn main () {
|
fn main () {
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
|
@ -23,31 +13,31 @@ fn main () {
|
||||||
|
|
||||||
let mut refs = HashSet::new();
|
let mut refs = HashSet::new();
|
||||||
|
|
||||||
// capture all links and link references
|
// Capture all links and link references.
|
||||||
let regex = r"\[([^\]]+)\](?:(?:\[([^\]]+)\])|(?:\([^\)]+\)))(?i)<!-- ignore -->";
|
let regex = r"\[([^\]]+)\](?:(?:\[([^\]]+)\])|(?:\([^\)]+\)))(?i)<!-- ignore -->";
|
||||||
let link_regex = Regex::new(regex).unwrap();
|
let link_regex = Regex::new(regex).unwrap();
|
||||||
let first_pass = link_regex.replace_all(&buffer, |caps: &Captures| {
|
let first_pass = link_regex.replace_all(&buffer, |caps: &Captures| {
|
||||||
|
|
||||||
// save the link reference we want to delete
|
// Save the link reference we want to delete.
|
||||||
if let Some(reference) = caps.at(2) {
|
if let Some(reference) = caps.at(2) {
|
||||||
refs.insert(reference.to_owned());
|
refs.insert(reference.to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
// put the link title back
|
// Put the link title back.
|
||||||
caps.at(1).unwrap().to_owned()
|
caps.at(1).unwrap().to_owned()
|
||||||
});
|
});
|
||||||
|
|
||||||
// search for the references we need to delete
|
// Search for the references we need to delete.
|
||||||
let ref_regex = Regex::new(r"\n\[([^\]]+)\]:\s.*\n").unwrap();
|
let ref_regex = Regex::new(r"\n\[([^\]]+)\]:\s.*\n").unwrap();
|
||||||
let out = ref_regex.replace_all(&first_pass, |caps: &Captures| {
|
let out = ref_regex.replace_all(&first_pass, |caps: &Captures| {
|
||||||
let capture = caps.at(1).unwrap().to_owned();
|
let capture = caps.at(1).unwrap().to_owned();
|
||||||
|
|
||||||
// check if we've marked this reference for deletion...
|
// Check if we've marked this reference for deletion ...
|
||||||
if refs.contains(capture.as_str()) {
|
if refs.contains(capture.as_str()) {
|
||||||
return "".to_string();
|
return "".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
//... else we put back everything we captured
|
// ... else we put back everything we captured.
|
||||||
caps.at(0).unwrap().to_owned()
|
caps.at(0).unwrap().to_owned()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,5 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use regex::{Regex, Captures};
|
use regex::{Regex, Captures};
|
||||||
|
@ -31,23 +22,23 @@ fn write_md(output: String) {
|
||||||
|
|
||||||
fn remove_markup(input: String) -> String {
|
fn remove_markup(input: String) -> String {
|
||||||
let filename_regex = Regex::new(r#"\A<span class="filename">(.*)</span>\z"#).unwrap();
|
let filename_regex = Regex::new(r#"\A<span class="filename">(.*)</span>\z"#).unwrap();
|
||||||
// Captions sometimes take up multiple lines
|
// Captions sometimes take up multiple lines.
|
||||||
let caption_start_regex = Regex::new(r#"\A<span class="caption">(.*)\z"#).unwrap();
|
let caption_start_regex = Regex::new(r#"\A<span class="caption">(.*)\z"#).unwrap();
|
||||||
let caption_end_regex = Regex::new(r#"(.*)</span>\z"#).unwrap();
|
let caption_end_regex = Regex::new(r#"(.*)</span>\z"#).unwrap();
|
||||||
let regexen = vec![filename_regex, caption_start_regex, caption_end_regex];
|
let regexen = vec![filename_regex, caption_start_regex, caption_end_regex];
|
||||||
|
|
||||||
let lines: Vec<_> = input.lines().flat_map(|line| {
|
let lines: Vec<_> = input.lines().flat_map(|line| {
|
||||||
// Remove our figure and caption markup
|
// Remove our figure and caption markup.
|
||||||
if line == "<figure>" ||
|
if line == "<figure>" ||
|
||||||
line == "<figcaption>" ||
|
line == "<figcaption>" ||
|
||||||
line == "</figcaption>" ||
|
line == "</figcaption>" ||
|
||||||
line == "</figure>"
|
line == "</figure>"
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
// Remove our syntax highlighting and rustdoc markers
|
// Remove our syntax highlighting and rustdoc markers.
|
||||||
} else if line.starts_with("```") {
|
} else if line.starts_with("```") {
|
||||||
Some(String::from("```"))
|
Some(String::from("```"))
|
||||||
// Remove the span around filenames and captions
|
// Remove the span around filenames and captions.
|
||||||
} else {
|
} else {
|
||||||
let result = regexen.iter().fold(line.to_string(), |result, regex| {
|
let result = regexen.iter().fold(line.to_string(), |result, regex| {
|
||||||
regex.replace_all(&result, |caps: &Captures| {
|
regex.replace_all(&result, |caps: &Captures| {
|
||||||
|
|
12
ci/build.sh
12
ci/build.sh
|
@ -1,18 +1,10 @@
|
||||||
# Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
#!/bin/bash
|
||||||
# file at the top-level directory of this distribution and at
|
|
||||||
# http://rust-lang.org/COPYRIGHT.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
# option. This file may not be copied, modified, or distributed
|
|
||||||
# except according to those terms.
|
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
export PATH=$PATH:/home/travis/.cargo/bin;
|
export PATH=$PATH:/home/travis/.cargo/bin;
|
||||||
|
|
||||||
# feature check
|
# Feature check
|
||||||
cd ci/stable-check
|
cd ci/stable-check
|
||||||
|
|
||||||
cargo run -- ../../src
|
cargo run -- ../../src
|
||||||
|
|
|
@ -1,17 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
# file at the top-level directory of this distribution and at
|
|
||||||
# http://rust-lang.org/COPYRIGHT.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
# option. This file may not be copied, modified, or distributed
|
|
||||||
# except according to those terms.
|
|
||||||
|
|
||||||
aspell --version
|
aspell --version
|
||||||
|
|
||||||
# Checks project markdown files for spell errors
|
# Checks project Markdown files for spelling mistakes.
|
||||||
|
|
||||||
# Notes:
|
# Notes:
|
||||||
|
|
||||||
|
@ -45,8 +36,8 @@ dict_filename=./ci/dictionary.txt
|
||||||
markdown_sources=(./src/*.md)
|
markdown_sources=(./src/*.md)
|
||||||
mode="check"
|
mode="check"
|
||||||
|
|
||||||
# aspell repeatedly modifies personal dictionary for some purpose,
|
# aspell repeatedly modifies the personal dictionary for some reason,
|
||||||
# so we should use a copy of our dictionary
|
# so we should use a copy of our dictionary.
|
||||||
dict_path="/tmp/dictionary.txt"
|
dict_path="/tmp/dictionary.txt"
|
||||||
|
|
||||||
if [[ "$1" == "list" ]]; then
|
if [[ "$1" == "list" ]]; then
|
||||||
|
@ -70,7 +61,7 @@ if [[ ! -f "$dict_filename" ]]; then
|
||||||
echo "personal_ws-1.1 en 0 utf-8" > "$dict_filename"
|
echo "personal_ws-1.1 en 0 utf-8" > "$dict_filename"
|
||||||
cat "${markdown_sources[@]}" | aspell --ignore 3 list | sort -u >> "$dict_filename"
|
cat "${markdown_sources[@]}" | aspell --ignore 3 list | sort -u >> "$dict_filename"
|
||||||
elif [[ "$mode" == "list" ]]; then
|
elif [[ "$mode" == "list" ]]; then
|
||||||
# List (default) mode: scan all files, report errors
|
# List (default) mode: scan all files, report errors.
|
||||||
declare -i retval=0
|
declare -i retval=0
|
||||||
|
|
||||||
cp "$dict_filename" "$dict_path"
|
cp "$dict_filename" "$dict_path"
|
||||||
|
@ -84,9 +75,9 @@ elif [[ "$mode" == "list" ]]; then
|
||||||
command=$(aspell --ignore 3 --personal="$dict_path" "$mode" < "$fname")
|
command=$(aspell --ignore 3 --personal="$dict_path" "$mode" < "$fname")
|
||||||
if [[ -n "$command" ]]; then
|
if [[ -n "$command" ]]; then
|
||||||
for error in $command; do
|
for error in $command; do
|
||||||
# FIXME: Find more correct way to get line number
|
# FIXME: find more correct way to get line number
|
||||||
# (ideally from aspell). Now it can make some false positives,
|
# (ideally from aspell). Now it can make some false positives,
|
||||||
# because it is just a grep
|
# because it is just a grep.
|
||||||
grep --with-filename --line-number --color=always "$error" "$fname"
|
grep --with-filename --line-number --color=always "$error" "$fname"
|
||||||
done
|
done
|
||||||
retval=1
|
retval=1
|
||||||
|
@ -94,7 +85,7 @@ elif [[ "$mode" == "list" ]]; then
|
||||||
done
|
done
|
||||||
exit "$retval"
|
exit "$retval"
|
||||||
elif [[ "$mode" == "check" ]]; then
|
elif [[ "$mode" == "check" ]]; then
|
||||||
# Interactive mode: fix typos
|
# Interactive mode: fix typos.
|
||||||
cp "$dict_filename" "$dict_path"
|
cp "$dict_filename" "$dict_path"
|
||||||
|
|
||||||
if [ ! -f $dict_path ]; then
|
if [ ! -f $dict_path ]; then
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
# file at the top-level directory of this distribution and at
|
|
||||||
# http://rust-lang.org/COPYRIGHT.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
# option. This file may not be copied, modified, or distributed
|
|
||||||
# except according to those terms.
|
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
|
19
nostarch.sh
19
nostarch.sh
|
@ -1,13 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
# file at the top-level directory of this distribution and at
|
|
||||||
# http://rust-lang.org/COPYRIGHT.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
# option. This file may not be copied, modified, or distributed
|
|
||||||
# except according to those terms.
|
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
@ -16,18 +7,18 @@ cargo build --release
|
||||||
mkdir -p tmp
|
mkdir -p tmp
|
||||||
rm -rf tmp/*.md
|
rm -rf tmp/*.md
|
||||||
|
|
||||||
# Get all the markdown files in the src dir,
|
# Get all the Markdown files in the src dir,
|
||||||
ls src/${1:-""}*.md | \
|
ls src/${1:-""}*.md | \
|
||||||
# except for SUMMARY.md.
|
# except for `SUMMARY.md`.
|
||||||
grep -v SUMMARY.md | \
|
grep -v SUMMARY.md | \
|
||||||
# Extract just the filename so we can reuse it easily.
|
# Extract just the filename so we can reuse it easily.
|
||||||
xargs -n 1 basename | \
|
xargs -n 1 basename | \
|
||||||
# Remove all links followed by <!-- ignore -->, then
|
# Remove all links followed by `<!-- ignore -->``, then
|
||||||
# Change all remaining links from markdown to italicized inline text.
|
# Change all remaining links from Markdown to italicized inline text.
|
||||||
while IFS= read -r filename; do
|
while IFS= read -r filename; do
|
||||||
< "src/$filename" ./target/release/remove_links \
|
< "src/$filename" ./target/release/remove_links \
|
||||||
| ./target/release/link2print \
|
| ./target/release/link2print \
|
||||||
| ./target/release/remove_markup > "tmp/$filename"
|
| ./target/release/remove_markup > "tmp/$filename"
|
||||||
done
|
done
|
||||||
# Concat the files into the nostarch dir.
|
# Concatenate the files into the `nostarch` dir.
|
||||||
./target/release/concat_chapters tmp nostarch
|
./target/release/concat_chapters tmp nostarch
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
# file at the top-level directory of this distribution and at
|
|
||||||
# http://rust-lang.org/COPYRIGHT.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
# option. This file may not be copied, modified, or distributed
|
|
||||||
# except according to those terms.
|
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
|
|
@ -1,29 +1,20 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
# file at the top-level directory of this distribution and at
|
|
||||||
# http://rust-lang.org/COPYRIGHT.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
# option. This file may not be copied, modified, or distributed
|
|
||||||
# except according to those terms.
|
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
# Get all the docx files in the tmp dir,
|
# Get all the docx files in the tmp dir.
|
||||||
ls tmp/*.docx | \
|
ls tmp/*.docx | \
|
||||||
# Extract just the filename so we can reuse it easily.
|
# Extract just the filename so we can reuse it easily.
|
||||||
xargs -n 1 basename -s .docx | \
|
xargs -n 1 basename -s .docx | \
|
||||||
while IFS= read -r filename; do
|
while IFS= read -r filename; do
|
||||||
# Make a directory to put the XML in
|
# Make a directory to put the XML in.
|
||||||
mkdir -p "tmp/$filename"
|
mkdir -p "tmp/$filename"
|
||||||
# Unzip the docx to get at the xml
|
# Unzip the docx to get at the XML.
|
||||||
unzip -o "tmp/$filename.docx" -d "tmp/$filename"
|
unzip -o "tmp/$filename.docx" -d "tmp/$filename"
|
||||||
# Convert to markdown with XSL
|
# Convert to markdown with XSL.
|
||||||
xsltproc tools/docx-to-md.xsl "tmp/$filename/word/document.xml" | \
|
xsltproc tools/docx-to-md.xsl "tmp/$filename/word/document.xml" | \
|
||||||
# Hard wrap at 80 chars at word bourdaries
|
# Hard wrap at 80 chars at word bourdaries.
|
||||||
fold -w 80 -s | \
|
fold -w 80 -s | \
|
||||||
# Remove trailing whitespace & save in the nostarch dir for comparison
|
# Remove trailing whitespace and save in the `nostarch` dir for comparison.
|
||||||
sed -e "s/ *$//" > "nostarch/$filename.md"
|
sed -e "s/ *$//" > "nostarch/$filename.md"
|
||||||
done
|
done
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
# file at the top-level directory of this distribution and at
|
|
||||||
# http://rust-lang.org/COPYRIGHT.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
# option. This file may not be copied, modified, or distributed
|
|
||||||
# except according to those terms.
|
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
@ -16,18 +7,18 @@ cargo build --release
|
||||||
mkdir -p tmp
|
mkdir -p tmp
|
||||||
rm -rf tmp/*.md
|
rm -rf tmp/*.md
|
||||||
|
|
||||||
# Get all the markdown files in the src dir,
|
# Get all the Markdown files in the src dir,
|
||||||
ls src/${1:-""}*.md | \
|
ls src/${1:-""}*.md | \
|
||||||
# except for SUMMARY.md.
|
# except for `SUMMARY.md`.
|
||||||
grep -v SUMMARY.md | \
|
grep -v SUMMARY.md | \
|
||||||
# Extract just the filename so we can reuse it easily.
|
# Extract just the filename so we can reuse it easily.
|
||||||
xargs -n 1 basename | \
|
xargs -n 1 basename | \
|
||||||
# Remove all links followed by <!-- ignore -->, then
|
# Remove all links followed by `<!-- ignore -->``, then
|
||||||
# Change all remaining links from markdown to italicized inline text.
|
# Change all remaining links from Markdown to italicized inline text.
|
||||||
while IFS= read -r filename; do
|
while IFS= read -r filename; do
|
||||||
< "src/$filename" ./target/release/remove_links \
|
< "src/$filename" ./target/release/remove_links \
|
||||||
| ./target/release/link2print \
|
| ./target/release/link2print \
|
||||||
| ./target/release/remove_markup > "tmp/$filename"
|
| ./target/release/remove_markup > "tmp/$filename"
|
||||||
done
|
done
|
||||||
# Concat the files into the nostarch dir.
|
# Concatenate the files into the `nostarch` dir.
|
||||||
./target/release/concat_chapters tmp nostarch
|
./target/release/concat_chapters tmp nostarch
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
#[macro_use] extern crate lazy_static;
|
#[macro_use] extern crate lazy_static;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
@ -22,7 +12,6 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for line in buffer.lines() {
|
for line in buffer.lines() {
|
||||||
|
|
||||||
if line.is_empty() {
|
if line.is_empty() {
|
||||||
is_in_inline_code = false;
|
is_in_inline_code = false;
|
||||||
}
|
}
|
||||||
|
@ -39,11 +28,11 @@ fn main() {
|
||||||
let mut chars_in_line = line.chars();
|
let mut chars_in_line = line.chars();
|
||||||
|
|
||||||
while let Some(possible_match) = chars_in_line.next() {
|
while let Some(possible_match) = chars_in_line.next() {
|
||||||
// check if inside inline code
|
// Check if inside inline code.
|
||||||
if possible_match == '`' {
|
if possible_match == '`' {
|
||||||
is_in_inline_code = !is_in_inline_code;
|
is_in_inline_code = !is_in_inline_code;
|
||||||
}
|
}
|
||||||
// check if inside html tag
|
// Check if inside HTML tag.
|
||||||
if possible_match == '<' && !is_in_inline_code {
|
if possible_match == '<' && !is_in_inline_code {
|
||||||
is_in_html_tag = true;
|
is_in_html_tag = true;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +40,7 @@ fn main() {
|
||||||
is_in_html_tag = false;
|
is_in_html_tag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace with right/left apostrophe/quote
|
// Replace with right/left apostrophe/quote.
|
||||||
let char_to_push =
|
let char_to_push =
|
||||||
if possible_match == '\'' && !is_in_inline_code && !is_in_html_tag {
|
if possible_match == '\'' && !is_in_inline_code && !is_in_html_tag {
|
||||||
if (previous_char != std::char::REPLACEMENT_CHARACTER &&
|
if (previous_char != std::char::REPLACEMENT_CHARACTER &&
|
||||||
|
@ -72,7 +61,7 @@ fn main() {
|
||||||
'“'
|
'“'
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// leave untouched
|
// Leave untouched.
|
||||||
possible_match
|
possible_match
|
||||||
};
|
};
|
||||||
modified_line.push(char_to_push);
|
modified_line.push(char_to_push);
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// We have some long regex literals, so:
|
// We have some long regex literals, so:
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,4 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
// FIXME: we have some long lines that could be refactored, but it's not a big deal.
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
|
|
||||||
// FIXME: We have some long lines that could be refactored, but it's not a big deal.
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
|
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
@ -20,7 +9,6 @@ use std::io::{Read, Write};
|
||||||
use regex::{Regex, Captures};
|
use regex::{Regex, Captures};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
write_md(parse_links(parse_references(read_md())));
|
write_md(parse_links(parse_references(read_md())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +26,7 @@ fn write_md(output: String) {
|
||||||
|
|
||||||
fn parse_references(buffer: String) -> (String, HashMap<String, String>) {
|
fn parse_references(buffer: String) -> (String, HashMap<String, String>) {
|
||||||
let mut ref_map = HashMap::new();
|
let mut ref_map = HashMap::new();
|
||||||
// FIXME: Currently doesn't handle "title" in following line
|
// FIXME: currently doesn't handle "title" in following line.
|
||||||
let re = Regex::new(r###"(?m)\n?^ {0,3}\[([^]]+)\]:[[:blank:]]*(.*)$"###).unwrap();
|
let re = Regex::new(r###"(?m)\n?^ {0,3}\[([^]]+)\]:[[:blank:]]*(.*)$"###).unwrap();
|
||||||
let output = re.replace_all(&buffer, |caps: &Captures| {
|
let output = re.replace_all(&buffer, |caps: &Captures| {
|
||||||
let key = caps.at(1).unwrap().to_owned().to_uppercase();
|
let key = caps.at(1).unwrap().to_owned().to_uppercase();
|
||||||
|
@ -52,7 +40,7 @@ fn parse_references(buffer: String) -> (String, HashMap<String, String>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
||||||
// FIXME: check which punctuation is allowed by spec
|
// FIXME: check which punctuation is allowed by spec.
|
||||||
let re = Regex::new(r###"(?:(?P<pre>(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P<name>[^]]+)\](?:(?:\([[:blank:]]*(?P<val>[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P<key>[^]]*)\]))?))"###).expect("could not create regex");
|
let re = Regex::new(r###"(?:(?P<pre>(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P<name>[^]]+)\](?:(?:\([[:blank:]]*(?P<val>[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P<key>[^]]*)\]))?))"###).expect("could not create regex");
|
||||||
let error_code = Regex::new(r###"^E\d{4}$"###).expect("could not create regex");
|
let error_code = Regex::new(r###"^E\d{4}$"###).expect("could not create regex");
|
||||||
let output = re.replace_all(&buffer, |caps: &Captures| {
|
let output = re.replace_all(&buffer, |caps: &Captures| {
|
||||||
|
@ -62,7 +50,7 @@ fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
||||||
let name = caps.name("name").expect("could not get name").to_owned();
|
let name = caps.name("name").expect("could not get name").to_owned();
|
||||||
// Really we should ignore text inside code blocks,
|
// Really we should ignore text inside code blocks,
|
||||||
// this is a hack to not try to treat `#[derive()]`,
|
// this is a hack to not try to treat `#[derive()]`,
|
||||||
// `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link
|
// `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link.
|
||||||
if name.starts_with("derive(") ||
|
if name.starts_with("derive(") ||
|
||||||
name.starts_with("profile") ||
|
name.starts_with("profile") ||
|
||||||
name.starts_with("test") ||
|
name.starts_with("test") ||
|
||||||
|
@ -71,7 +59,7 @@ fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
let val = match caps.name("val") {
|
let val = match caps.name("val") {
|
||||||
// [name](link)
|
// `[name](link)`
|
||||||
Some(value) => value.to_owned(),
|
Some(value) => value.to_owned(),
|
||||||
None => {
|
None => {
|
||||||
match caps.name("key") {
|
match caps.name("key") {
|
||||||
|
@ -83,7 +71,7 @@ fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
||||||
_ => format!("{}", ref_map.get(&key.to_uppercase()).expect(&format!("could not find url for the link text `{}`", key))),
|
_ => format!("{}", ref_map.get(&key.to_uppercase()).expect(&format!("could not find url for the link text `{}`", key))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// [name] as reference
|
// `[name]` as reference
|
||||||
None => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
|
None => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,7 +403,4 @@ Some text to show that the reference links can follow later.
|
||||||
.to_string();
|
.to_string();
|
||||||
assert_eq!(parse(source), target);
|
assert_eq!(parse(source), target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
@ -23,31 +13,31 @@ fn main () {
|
||||||
|
|
||||||
let mut refs = HashSet::new();
|
let mut refs = HashSet::new();
|
||||||
|
|
||||||
// capture all links and link references
|
// Capture all links and link references.
|
||||||
let regex = r"\[([^\]]+)\](?:(?:\[([^\]]+)\])|(?:\([^\)]+\)))(?i)<!-- ignore -->";
|
let regex = r"\[([^\]]+)\](?:(?:\[([^\]]+)\])|(?:\([^\)]+\)))(?i)<!-- ignore -->";
|
||||||
let link_regex = Regex::new(regex).unwrap();
|
let link_regex = Regex::new(regex).unwrap();
|
||||||
let first_pass = link_regex.replace_all(&buffer, |caps: &Captures| {
|
let first_pass = link_regex.replace_all(&buffer, |caps: &Captures| {
|
||||||
|
|
||||||
// save the link reference we want to delete
|
// Save the link reference we want to delete.
|
||||||
if let Some(reference) = caps.at(2) {
|
if let Some(reference) = caps.at(2) {
|
||||||
refs.insert(reference.to_owned());
|
refs.insert(reference.to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
// put the link title back
|
// Put the link title back.
|
||||||
caps.at(1).unwrap().to_owned()
|
caps.at(1).unwrap().to_owned()
|
||||||
});
|
});
|
||||||
|
|
||||||
// search for the references we need to delete
|
// Search for the references we need to delete.
|
||||||
let ref_regex = Regex::new(r"\n\[([^\]]+)\]:\s.*\n").unwrap();
|
let ref_regex = Regex::new(r"\n\[([^\]]+)\]:\s.*\n").unwrap();
|
||||||
let out = ref_regex.replace_all(&first_pass, |caps: &Captures| {
|
let out = ref_regex.replace_all(&first_pass, |caps: &Captures| {
|
||||||
let capture = caps.at(1).unwrap().to_owned();
|
let capture = caps.at(1).unwrap().to_owned();
|
||||||
|
|
||||||
// check if we've marked this reference for deletion...
|
// Check if we've marked this reference for deletion ...
|
||||||
if refs.contains(capture.as_str()) {
|
if refs.contains(capture.as_str()) {
|
||||||
return "".to_string();
|
return "".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
//... else we put back everything we captured
|
// ... else we put back everything we captured.
|
||||||
caps.at(0).unwrap().to_owned()
|
caps.at(0).unwrap().to_owned()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,5 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use regex::{Regex, Captures};
|
use regex::{Regex, Captures};
|
||||||
|
@ -31,23 +22,23 @@ fn write_md(output: String) {
|
||||||
|
|
||||||
fn remove_markup(input: String) -> String {
|
fn remove_markup(input: String) -> String {
|
||||||
let filename_regex = Regex::new(r#"\A<span class="filename">(.*)</span>\z"#).unwrap();
|
let filename_regex = Regex::new(r#"\A<span class="filename">(.*)</span>\z"#).unwrap();
|
||||||
// Captions sometimes take up multiple lines
|
// Captions sometimes take up multiple lines.
|
||||||
let caption_start_regex = Regex::new(r#"\A<span class="caption">(.*)\z"#).unwrap();
|
let caption_start_regex = Regex::new(r#"\A<span class="caption">(.*)\z"#).unwrap();
|
||||||
let caption_end_regex = Regex::new(r#"(.*)</span>\z"#).unwrap();
|
let caption_end_regex = Regex::new(r#"(.*)</span>\z"#).unwrap();
|
||||||
let regexen = vec![filename_regex, caption_start_regex, caption_end_regex];
|
let regexen = vec![filename_regex, caption_start_regex, caption_end_regex];
|
||||||
|
|
||||||
let lines: Vec<_> = input.lines().flat_map(|line| {
|
let lines: Vec<_> = input.lines().flat_map(|line| {
|
||||||
// Remove our figure and caption markup
|
// Remove our figure and caption markup.
|
||||||
if line == "<figure>" ||
|
if line == "<figure>" ||
|
||||||
line == "<figcaption>" ||
|
line == "<figcaption>" ||
|
||||||
line == "</figcaption>" ||
|
line == "</figcaption>" ||
|
||||||
line == "</figure>"
|
line == "</figure>"
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
// Remove our syntax highlighting and rustdoc markers
|
// Remove our syntax highlighting and rustdoc markers.
|
||||||
} else if line.starts_with("```") {
|
} else if line.starts_with("```") {
|
||||||
Some(String::from("```"))
|
Some(String::from("```"))
|
||||||
// Remove the span around filenames and captions
|
// Remove the span around filenames and captions.
|
||||||
} else {
|
} else {
|
||||||
let result = regexen.iter().fold(line.to_string(), |result, regex| {
|
let result = regexen.iter().fold(line.to_string(), |result, regex| {
|
||||||
regex.replace_all(&result, |caps: &Captures| {
|
regex.replace_all(&result, |caps: &Captures| {
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
#[macro_use] extern crate lazy_static;
|
#[macro_use] extern crate lazy_static;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
@ -39,11 +29,11 @@ fn main() {
|
||||||
let mut chars_in_line = line.chars();
|
let mut chars_in_line = line.chars();
|
||||||
|
|
||||||
while let Some(possible_match) = chars_in_line.next() {
|
while let Some(possible_match) = chars_in_line.next() {
|
||||||
// check if inside inline code
|
// Check if inside inline code.
|
||||||
if possible_match == '`' {
|
if possible_match == '`' {
|
||||||
is_in_inline_code = !is_in_inline_code;
|
is_in_inline_code = !is_in_inline_code;
|
||||||
}
|
}
|
||||||
// check if inside html tag
|
// Check if inside HTML tag.
|
||||||
if possible_match == '<' && !is_in_inline_code {
|
if possible_match == '<' && !is_in_inline_code {
|
||||||
is_in_html_tag = true;
|
is_in_html_tag = true;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +41,7 @@ fn main() {
|
||||||
is_in_html_tag = false;
|
is_in_html_tag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace with right/left apostrophe/quote
|
// Replace with right/left apostrophe/quote.
|
||||||
let char_to_push =
|
let char_to_push =
|
||||||
if possible_match == '\'' && !is_in_inline_code && !is_in_html_tag {
|
if possible_match == '\'' && !is_in_inline_code && !is_in_html_tag {
|
||||||
if (previous_char != std::char::REPLACEMENT_CHARACTER &&
|
if (previous_char != std::char::REPLACEMENT_CHARACTER &&
|
||||||
|
@ -72,7 +62,7 @@ fn main() {
|
||||||
'“'
|
'“'
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// leave untouched
|
// Leave untouched.
|
||||||
possible_match
|
possible_match
|
||||||
};
|
};
|
||||||
modified_line.push(char_to_push);
|
modified_line.push(char_to_push);
|
||||||
|
|
|
@ -1,20 +1,11 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// We have some long regex literals, so:
|
// We have some long regex literals, so:
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
|
|
||||||
|
extern crate docopt;
|
||||||
|
extern crate rustc_serialize;
|
||||||
|
extern crate walkdir;
|
||||||
|
|
||||||
use docopt::Docopt;
|
use docopt::Docopt;
|
||||||
use walkdir;
|
|
||||||
use std::{path, fs, io};
|
use std::{path, fs, io};
|
||||||
use std::io::{BufRead, Write};
|
use std::io::{BufRead, Write};
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,4 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
// FIXME: we have some long lines that could be refactored, but it's not a big deal.
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
|
|
||||||
// FIXME: We have some long lines that could be refactored, but it's not a big deal.
|
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +9,6 @@ use std::io::{Read, Write};
|
||||||
use regex::{Regex, Captures};
|
use regex::{Regex, Captures};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
write_md(parse_links(parse_references(read_md())));
|
write_md(parse_links(parse_references(read_md())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +26,7 @@ fn write_md(output: String) {
|
||||||
|
|
||||||
fn parse_references(buffer: String) -> (String, HashMap<String, String>) {
|
fn parse_references(buffer: String) -> (String, HashMap<String, String>) {
|
||||||
let mut ref_map = HashMap::new();
|
let mut ref_map = HashMap::new();
|
||||||
// FIXME: Currently doesn't handle "title" in following line
|
// FIXME: currently doesn't handle "title" in following line.
|
||||||
let re = Regex::new(r###"(?m)\n?^ {0,3}\[([^]]+)\]:[[:blank:]]*(.*)$"###).unwrap();
|
let re = Regex::new(r###"(?m)\n?^ {0,3}\[([^]]+)\]:[[:blank:]]*(.*)$"###).unwrap();
|
||||||
let output = re.replace_all(&buffer, |caps: &Captures<'_>| {
|
let output = re.replace_all(&buffer, |caps: &Captures<'_>| {
|
||||||
let key = caps.at(1).unwrap().to_owned().to_uppercase();
|
let key = caps.at(1).unwrap().to_owned().to_uppercase();
|
||||||
|
@ -52,7 +40,7 @@ fn parse_references(buffer: String) -> (String, HashMap<String, String>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
||||||
// FIXME: check which punctuation is allowed by spec
|
// FIXME: check which punctuation is allowed by spec.
|
||||||
let re = Regex::new(r###"(?:(?P<pre>(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P<name>[^]]+)\](?:(?:\([[:blank:]]*(?P<val>[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P<key>[^]]*)\]))?))"###).expect("could not create regex");
|
let re = Regex::new(r###"(?:(?P<pre>(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P<name>[^]]+)\](?:(?:\([[:blank:]]*(?P<val>[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P<key>[^]]*)\]))?))"###).expect("could not create regex");
|
||||||
let error_code = Regex::new(r###"^E\d{4}$"###).expect("could not create regex");
|
let error_code = Regex::new(r###"^E\d{4}$"###).expect("could not create regex");
|
||||||
let output = re.replace_all(&buffer, |caps: &Captures<'_>| {
|
let output = re.replace_all(&buffer, |caps: &Captures<'_>| {
|
||||||
|
@ -62,7 +50,7 @@ fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
||||||
let name = caps.name("name").expect("could not get name").to_owned();
|
let name = caps.name("name").expect("could not get name").to_owned();
|
||||||
// Really we should ignore text inside code blocks,
|
// Really we should ignore text inside code blocks,
|
||||||
// this is a hack to not try to treat `#[derive()]`,
|
// this is a hack to not try to treat `#[derive()]`,
|
||||||
// `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link
|
// `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link.
|
||||||
if name.starts_with("derive(") ||
|
if name.starts_with("derive(") ||
|
||||||
name.starts_with("profile") ||
|
name.starts_with("profile") ||
|
||||||
name.starts_with("test") ||
|
name.starts_with("test") ||
|
||||||
|
@ -71,19 +59,19 @@ fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
let val = match caps.name("val") {
|
let val = match caps.name("val") {
|
||||||
// [name](link)
|
// `[name](link)`
|
||||||
Some(value) => value.to_owned(),
|
Some(value) => value.to_owned(),
|
||||||
None => {
|
None => {
|
||||||
match caps.name("key") {
|
match caps.name("key") {
|
||||||
Some(key) => {
|
Some(key) => {
|
||||||
match key {
|
match key {
|
||||||
// [name][]
|
// `[name][]`
|
||||||
"" => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
|
"" => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
|
||||||
// [name][reference]
|
// `[name][reference]`
|
||||||
_ => format!("{}", ref_map.get(&key.to_uppercase()).expect(&format!("could not find url for the link text `{}`", key))),
|
_ => format!("{}", ref_map.get(&key.to_uppercase()).expect(&format!("could not find url for the link text `{}`", key))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// [name] as reference
|
// `[name]` as reference
|
||||||
None => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
|
None => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,7 +403,4 @@ Some text to show that the reference links can follow later.
|
||||||
.to_string();
|
.to_string();
|
||||||
assert_eq!(parse(source), target);
|
assert_eq!(parse(source), target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,9 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
extern crate regex;
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use regex::{Regex, Captures};
|
use regex::{Regex, Captures};
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
fn main () {
|
fn main () {
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
|
@ -23,31 +13,31 @@ fn main () {
|
||||||
|
|
||||||
let mut refs = HashSet::new();
|
let mut refs = HashSet::new();
|
||||||
|
|
||||||
// capture all links and link references
|
// Capture all links and link references.
|
||||||
let regex = r"\[([^\]]+)\](?:(?:\[([^\]]+)\])|(?:\([^\)]+\)))(?i)<!-- ignore -->";
|
let regex = r"\[([^\]]+)\](?:(?:\[([^\]]+)\])|(?:\([^\)]+\)))(?i)<!-- ignore -->";
|
||||||
let link_regex = Regex::new(regex).unwrap();
|
let link_regex = Regex::new(regex).unwrap();
|
||||||
let first_pass = link_regex.replace_all(&buffer, |caps: &Captures<'_>| {
|
let first_pass = link_regex.replace_all(&buffer, |caps: &Captures<'_>| {
|
||||||
|
|
||||||
// save the link reference we want to delete
|
// Save the link reference we want to delete.
|
||||||
if let Some(reference) = caps.at(2) {
|
if let Some(reference) = caps.at(2) {
|
||||||
refs.insert(reference.to_owned());
|
refs.insert(reference.to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
// put the link title back
|
// Put the link title back.
|
||||||
caps.at(1).unwrap().to_owned()
|
caps.at(1).unwrap().to_owned()
|
||||||
});
|
});
|
||||||
|
|
||||||
// search for the references we need to delete
|
// Search for the references we need to delete.
|
||||||
let ref_regex = Regex::new(r"\n\[([^\]]+)\]:\s.*\n").unwrap();
|
let ref_regex = Regex::new(r"\n\[([^\]]+)\]:\s.*\n").unwrap();
|
||||||
let out = ref_regex.replace_all(&first_pass, |caps: &Captures<'_>| {
|
let out = ref_regex.replace_all(&first_pass, |caps: &Captures<'_>| {
|
||||||
let capture = caps.at(1).unwrap().to_owned();
|
let capture = caps.at(1).unwrap().to_owned();
|
||||||
|
|
||||||
// check if we've marked this reference for deletion...
|
// Check if we've marked this reference for deletion ...
|
||||||
if refs.contains(capture.as_str()) {
|
if refs.contains(capture.as_str()) {
|
||||||
return "".to_string();
|
return "".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
//... else we put back everything we captured
|
// ... else we put back everything we captured.
|
||||||
caps.at(0).unwrap().to_owned()
|
caps.at(0).unwrap().to_owned()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
extern crate regex;
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
@ -31,23 +22,23 @@ fn write_md(output: String) {
|
||||||
|
|
||||||
fn remove_markup(input: String) -> String {
|
fn remove_markup(input: String) -> String {
|
||||||
let filename_regex = Regex::new(r#"\A<span class="filename">(.*)</span>\z"#).unwrap();
|
let filename_regex = Regex::new(r#"\A<span class="filename">(.*)</span>\z"#).unwrap();
|
||||||
// Captions sometimes take up multiple lines
|
// Captions sometimes take up multiple lines.
|
||||||
let caption_start_regex = Regex::new(r#"\A<span class="caption">(.*)\z"#).unwrap();
|
let caption_start_regex = Regex::new(r#"\A<span class="caption">(.*)\z"#).unwrap();
|
||||||
let caption_end_regex = Regex::new(r#"(.*)</span>\z"#).unwrap();
|
let caption_end_regex = Regex::new(r#"(.*)</span>\z"#).unwrap();
|
||||||
let regexen = vec![filename_regex, caption_start_regex, caption_end_regex];
|
let regexen = vec![filename_regex, caption_start_regex, caption_end_regex];
|
||||||
|
|
||||||
let lines: Vec<_> = input.lines().flat_map(|line| {
|
let lines: Vec<_> = input.lines().flat_map(|line| {
|
||||||
// Remove our figure and caption markup
|
// Remove our figure and caption markup.
|
||||||
if line == "<figure>" ||
|
if line == "<figure>" ||
|
||||||
line == "<figcaption>" ||
|
line == "<figcaption>" ||
|
||||||
line == "</figcaption>" ||
|
line == "</figcaption>" ||
|
||||||
line == "</figure>"
|
line == "</figure>"
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
// Remove our syntax highlighting and rustdoc markers
|
// Remove our syntax highlighting and rustdoc markers.
|
||||||
} else if line.starts_with("```") {
|
} else if line.starts_with("```") {
|
||||||
Some(String::from("```"))
|
Some(String::from("```"))
|
||||||
// Remove the span around filenames and captions
|
// Remove the span around filenames and captions.
|
||||||
} else {
|
} else {
|
||||||
let result = regexen.iter().fold(line.to_string(), |result, regex| {
|
let result = regexen.iter().fold(line.to_string(), |result, regex| {
|
||||||
regex.replace_all(&result, |caps: &Captures<'_>| {
|
regex.replace_all(&result, |caps: &Captures<'_>| {
|
||||||
|
|
Loading…
Reference in New Issue