File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99
1010## Unreleased
1111
12+ * Fix issue where Rosey would unescape characters that were entity encoded in the source HTML.
13+
1214## v2.3.0 (October 31, 2024)
1315
1416* Added ` data-rosey-ignore ` attribute to ignore hrefs when rewriting pages.
Original file line number Diff line number Diff line change 1+ Feature : Rosey Build Code Blocks
2+ Background :
3+ Given I have the environment variables:
4+ | ROSEY_SOURCE | dist /site |
5+ | ROSEY_DEST | dist /translated_site |
6+
7+ Scenario : Rosey doesn't ruin innocent escaped code
8+ Given I have a "dist/site/index.html" file with the content:
9+ """
10+ <html>
11+ <body>
12+ <div data-rosey="seal">Kiss From A Rose</div>
13+ <pre><code><configuration><setting v='true'/></configuration></code></pre>
14+ </body>
15+ </html>
16+ """
17+ And I have a "rosey/locales/manuka.json" file with the content:
18+ """
19+ {
20+ "seal": "Pollen From A Tree"
21+ }
22+ """
23+ When I run my program with the flags:
24+ | build |
25+ Then I should see a selector '[data-rosey="seal"]' in "dist/translated_site/manuka/index.html" with the attributes:
26+ | data -rosey | seal |
27+ | innerText | Pollen From A Tree |
28+ Then I should see a selector 'pre > code' in "dist/translated_site/manuka/index.html" with the attributes:
29+ | innerText | <configuration ><setting v ='true '/></configuration > |
Original file line number Diff line number Diff line change 1+ Feature : Rosey Generate Code Blocks
2+ Background :
3+ Given I have the environment variables:
4+ | ROSEY_SOURCE | dist /site |
5+ | ROSEY_DEST | dist /translated_site |
6+
7+ Scenario : Rosey generates base.json files with escaped code
8+ Given I have a "dist/site/index.html" file with the content:
9+ """
10+ <html>
11+ <body data-rosey-ns='home'>
12+ <div data-rosey="seal">Kiss From A Rose</div>
13+ <pre><code data-rosey="code"><configuration><setting v='true'/></configuration></code></pre>
14+ </body>
15+ </html>
16+ """
17+ When I run my program with the flags:
18+ | generate |
19+ Then I should see "rosey/base.json" containing the values:
20+ | version | int :2 |
21+ | keys .home :seal .original | Kiss From A Rose |
22+ | keys .home :code .original | < ;configuration > ;< ;setting v ='true '/> ;< ;/configuration > ; |
Original file line number Diff line number Diff line change @@ -342,3 +342,14 @@ pub fn inline_templates(dom: &kuchiki::NodeRef) {
342342 }
343343 } )
344344}
345+
346+ pub fn escape_source_text ( dom : & kuchiki:: NodeRef ) {
347+ dom. children ( ) . for_each ( |node| {
348+ if let Some ( text_node) = node. as_text ( ) {
349+ text_node. replace_with ( |old| old. replace ( '<' , "<" ) . replace ( '>' , ">" ) ) ;
350+ } else {
351+ node. descendants ( )
352+ . for_each ( |node| escape_source_text ( & node) ) ;
353+ }
354+ } ) ;
355+ }
Original file line number Diff line number Diff line change @@ -246,6 +246,7 @@ impl<'a> RoseyPage<'a> {
246246 ) -> Self {
247247 let dom = kuchiki:: parse_html ( ) . one ( content) ;
248248 crate :: inline_templates ( & dom) ;
249+ crate :: escape_source_text ( & dom) ;
249250
250251 RoseyPage {
251252 dom,
You can’t perform that action at this time.
0 commit comments