@@ -11,11 +11,9 @@ use std::collections::BTreeMap;
1111use std:: io;
1212use std:: path:: PathBuf ;
1313
14+ mod rules;
1415mod std_links;
1516
16- /// The Regex for rules like `r[foo]`.
17- static RULE_RE : Lazy < Regex > = Lazy :: new ( || Regex :: new ( r"(?m)^r\[([^]]+)]$" ) . unwrap ( ) ) ;
18-
1917/// The Regex for the syntax for blockquotes that have a specific CSS class,
2018/// like `> [!WARNING]`.
2119static ADMONITION_RE : Lazy < Regex > = Lazy :: new ( || {
@@ -57,41 +55,6 @@ impl Spec {
5755 }
5856 }
5957
60- /// Converts lines that start with `r[…]` into a "rule" which has special
61- /// styling and can be linked to.
62- fn rule_definitions (
63- & self ,
64- chapter : & Chapter ,
65- found_rules : & mut BTreeMap < String , ( PathBuf , PathBuf ) > ,
66- ) -> String {
67- let source_path = chapter. source_path . clone ( ) . unwrap_or_default ( ) ;
68- let path = chapter. path . clone ( ) . unwrap_or_default ( ) ;
69- RULE_RE
70- . replace_all ( & chapter. content , |caps : & Captures < ' _ > | {
71- let rule_id = & caps[ 1 ] ;
72- if let Some ( ( old, _) ) =
73- found_rules. insert ( rule_id. to_string ( ) , ( source_path. clone ( ) , path. clone ( ) ) )
74- {
75- let message = format ! (
76- "rule `{rule_id}` defined multiple times\n \
77- First location: {old:?}\n \
78- Second location: {source_path:?}"
79- ) ;
80- if self . deny_warnings {
81- panic ! ( "error: {message}" ) ;
82- } else {
83- eprintln ! ( "warning: {message}" ) ;
84- }
85- }
86- format ! (
87- "<div class=\" rule\" id=\" r-{rule_id}\" >\
88- <a class=\" rule-link\" href=\" #r-{rule_id}\" >[{rule_id}]</a>\
89- </div>\n "
90- )
91- } )
92- . to_string ( )
93- }
94-
9558 /// Generates link references to all rules on all pages, so you can easily
9659 /// refer to rules anywhere in the book.
9760 fn auto_link_references (
0 commit comments