Skip to content

Commit eda32de

Browse files
committed
Give up on automated translation for now
1 parent a3134ae commit eda32de

28 files changed

+47
-11500
lines changed

_build.R

+47-47
Original file line numberDiff line numberDiff line change
@@ -23,53 +23,53 @@ chapters %>% walk(
2323
)
2424

2525
# Convert from md to asciidoc ---------------------------------------------
26-
27-
replace_lines <- function(file, pattern, replacement, comments = FALSE) {
28-
str_replace_all(file, regex(pattern, multiline = TRUE, comments = comments), replacement)
29-
}
30-
31-
# Regular expressions mostly contributed by Nicholas Adams, O'Reilly
32-
md2asciidoc <- function(file) {
33-
# Headings with and without ids
34-
file <- replace_lines(file, r"(
35-
^\#\ \(PART\\\*\) # standard part marker
36-
(.*?)\ # title
37-
\{\#
38-
([-a-zA-Z]+) # id
39-
(\ .unnumbered)?
40-
\}
41-
)", "[part]\n== \\1", comments = TRUE)
42-
file <- replace_lines(file, '(^# )(.*?)(\\{#)(.*?)(\\})', '[[\\4]]\n== \\2') # Chapter heading with ID
43-
file <- replace_lines(file, '(^# )(.*?)(\\{#)(.*?)(\\})', '[[\\4]]\n== \\2') # Chapter heading with ID
44-
file <- replace_lines(file, '(^## )(.*?)(\\{#)(.*?)(\\})', '[[\\4]]\n=== \\2') # A-Head with ID
45-
file <- replace_lines(file, '(^## )(.*?)', '=== \\2') # A-Head no ID
46-
file <- replace_lines(file, '(^### )(.*?)(\\{#)(.*?)(\\})', '[[\\4]]\n==== \\2') # B-Head with ID
47-
file <- replace_lines(file, '(^### )(.*?)', '==== \\2') # B-Head no ID
48-
49-
# Code blocks
50-
file <- replace_lines(file, '(^ *)(```)(.*?)(\n)((.|\n)*?)(```)', '\\1[source,\\3]\n\\1----\n\\5----')
51-
52-
# Figures
53-
file <- replace_lines(file, '(<img src=")(.*?)(")(.*?)(/>)(\n)(<p class="caption">)\n(.*?)\n(</p>)', '.\\8\nimage::\\2["\\8"]')
54-
file <- replace_lines(file, '(<img src=")(.*?)(")(.*?)(/>)', 'image::\\2[]')
55-
file <- replace_lines(file, '(::: \\{.figure\\})((.|\n)*?)(:::)', '\\2') # Remove figures
56-
57-
# Cross refs
58-
file <- replace_lines(file, '(Section )(\\\\@ref\\()(.*?)(\\))', '<<\\3>>') # Section
59-
file <- replace_lines(file, '(Chapter )(\\\\@ref\\()(.*?)(\\))', '<<\\3>>') # Chapter
60-
file <- replace_lines(file, '(Figure )(\\\\@ref\\()(fig:)(.*?)(\\))', '<<fig-\\4>>') # Figures
61-
62-
# Other formatting
63-
file <- replace_lines(file, '(::: \\{.rmdnote\\})((.|\n)*?)(:::)', '****\\2****') # Sidebar
64-
file <- replace_lines(file, '(<https:)(.*?)(>)', 'https:\\2[]') # Links
65-
file <- replace_lines(file, '(\\[.*?\\])(\\()(https?:)(.*?)(\\))', '\\3\\4\\1') # Links with anchor text
66-
file <- replace_lines(file, '(\\[\\^.*?\\])((.|\n)*?)(\\1: )(.*?)(\n)', 'footnote:[\\5]\\2') # Footnotes
67-
file
68-
}
69-
70-
asciidoc <- chapters_md %>% map(~ md2asciidoc(read_file(.)))
71-
72-
walk2(asciidoc, path_ext_set(chapters_md, ".asciidoc"), write_file)
26+
#
27+
# replace_lines <- function(file, pattern, replacement, comments = FALSE) {
28+
# str_replace_all(file, regex(pattern, multiline = TRUE, comments = comments), replacement)
29+
# }
30+
#
31+
# # Regular expressions mostly contributed by Nicholas Adams, O'Reilly
32+
# md2asciidoc <- function(file) {
33+
# # Headings with and without ids
34+
# file <- replace_lines(file, r"(
35+
# ^\#\ \(PART\\\*\) # standard part marker
36+
# (.*?)\ # title
37+
# \{\#
38+
# ([-a-zA-Z]+) # id
39+
# (\ .unnumbered)?
40+
# \}
41+
# )", "[part]\n== \\1", comments = TRUE)
42+
# file <- replace_lines(file, '(^# )(.*?)(\\{#)(.*?)(\\})', '[[\\4]]\n== \\2') # Chapter heading with ID
43+
# file <- replace_lines(file, '(^# )(.*?)(\\{#)(.*?)(\\})', '[[\\4]]\n== \\2') # Chapter heading with ID
44+
# file <- replace_lines(file, '(^## )(.*?)(\\{#)(.*?)(\\})', '[[\\4]]\n=== \\2') # A-Head with ID
45+
# file <- replace_lines(file, '(^## )(.*?)', '=== \\2') # A-Head no ID
46+
# file <- replace_lines(file, '(^### )(.*?)(\\{#)(.*?)(\\})', '[[\\4]]\n==== \\2') # B-Head with ID
47+
# file <- replace_lines(file, '(^### )(.*?)', '==== \\2') # B-Head no ID
48+
#
49+
# # Code blocks
50+
# file <- replace_lines(file, '(^ *)(```)(.*?)(\n)((.|\n)*?)(```)', '\\1[source,\\3]\n\\1----\n\\5----')
51+
#
52+
# # Figures
53+
# file <- replace_lines(file, '(<img src=")(.*?)(")(.*?)(/>)(\n)(<p class="caption">)\n(.*?)\n(</p>)', '.\\8\nimage::\\2["\\8"]')
54+
# file <- replace_lines(file, '(<img src=")(.*?)(")(.*?)(/>)', 'image::\\2[]')
55+
# file <- replace_lines(file, '(::: \\{.figure\\})((.|\n)*?)(:::)', '\\2') # Remove figures
56+
#
57+
# # Cross refs
58+
# file <- replace_lines(file, '(Section )(\\\\@ref\\()(.*?)(\\))', '<<\\3>>') # Section
59+
# file <- replace_lines(file, '(Chapter )(\\\\@ref\\()(.*?)(\\))', '<<\\3>>') # Chapter
60+
# file <- replace_lines(file, '(Figure )(\\\\@ref\\()(fig:)(.*?)(\\))', '<<fig-\\4>>') # Figures
61+
#
62+
# # Other formatting
63+
# file <- replace_lines(file, '(::: \\{.rmdnote\\})((.|\n)*?)(:::)', '****\\2****') # Sidebar
64+
# file <- replace_lines(file, '(<https:)(.*?)(>)', 'https:\\2[]') # Links
65+
# file <- replace_lines(file, '(\\[.*?\\])(\\()(https?:)(.*?)(\\))', '\\3\\4\\1') # Links with anchor text
66+
# file <- replace_lines(file, '(\\[\\^.*?\\])((.|\n)*?)(\\1: )(.*?)(\n)', 'footnote:[\\5]\\2') # Footnotes
67+
# file
68+
# }
69+
#
70+
# asciidoc <- chapters_md %>% map(~ md2asciidoc(read_file(.)))
71+
#
72+
# walk2(asciidoc, path_ext_set(chapters_md, ".asciidoc"), write_file)
7373

7474
# Copy over images ------------------------------------------------------------
7575

_oreilly/action-bookmark.asciidoc

-209
This file was deleted.

0 commit comments

Comments
 (0)