From e4b96b759f7485f3002a590b6f53532eb29c2f64 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 14 Jun 2019 15:42:21 -0400 Subject: [PATCH] user guide: implement section links --- doc/user_guide.md | 6 +++--- rb/gen_user_guide.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/user_guide.md b/doc/user_guide.md index 8ba221d..61d5e0c 100644 --- a/doc/user_guide.md +++ b/doc/user_guide.md @@ -77,8 +77,8 @@ source files. To use Rscons on your project, you must: - 1. Install the `rscons` script in your project (See [#Installation]). - 2. Write the `Rsconscript` build script for your project (See [#The Build Script]). + 1. Install the `rscons` script in your project (See ${#Installation}). + 2. Write the `Rsconscript` build script for your project (See ${#The Build Script}). # Installation @@ -418,7 +418,7 @@ found recursively under the `src` or `test` directory. Construction variables are values assigned to keys within an Environment. Construction variables are used by Builders to produce output files. -See [#Default Construction Variables] for a reference of all built-in +See ${#Default Construction Variables} for a reference of all built-in construction variables. Example: diff --git a/rb/gen_user_guide.rb b/rb/gen_user_guide.rb index 5d3659a..15af9c7 100644 --- a/rb/gen_user_guide.rb +++ b/rb/gen_user_guide.rb @@ -79,6 +79,11 @@ class Generator end changelog = @markdown_renderer.render(File.read("CHANGELOG.md")) content.gsub!("${changelog}", changelog) + content.gsub!(%r{\$\{#(.+?)\}}) do |match| + section_name = $1 + href = get_link_to_section(section_name) + %[#{section_name}] + end template = File.read("rb/assets/user_guide.html.erb") erb = ERB.new(template, nil, "<>") @@ -92,6 +97,14 @@ class Generator "s" + ("#{section_number} #{section_title}").gsub(/[^a-zA-Z0-9]/, "_") end + def get_link_to_section(section_name) + section = @sections.find do |section| + section.title == section_name + end + raise "Could not find section #{section_name}" unless section + "#{section.page}##{section.anchor}" + end + def gather_code_section(syntax) code = "" loop do