From 44768418d072d61d9b021b5007303a7f44be976d Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Sun, 24 Jan 2016 22:10:44 +0100 Subject: [PATCH] add hyphenation support - via --hyphenate argument to serve/generate-html --- dub.json | 3 ++- dub.selections.json | 5 +++-- source/ddox/ddoc.d | 35 +++++++++++++++++++++++++++++++++-- source/ddox/main.d | 23 ++++++++++++++--------- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/dub.json b/dub.json index 507d88be..827fe657 100644 --- a/dub.json +++ b/dub.json @@ -8,7 +8,8 @@ ], "dependencies": { "vibe-d": "~>0.7.22", - "libdparse": {"optional": true, "version": "~>0.2.0"} + "libdparse": {"optional": true, "version": "~>0.2.0"}, + "hyphenate": "~>1.1.0" }, "versions": ["JsonLineNumbers"], "configurations": [ diff --git a/dub.selections.json b/dub.selections.json index 10bfa141..26aac340 100644 --- a/dub.selections.json +++ b/dub.selections.json @@ -4,9 +4,10 @@ "libevent": "2.0.1+2.0.16", "libev": "5.0.0+4.04", "openssl": "1.1.4+1.0.1g", + "libdparse": "0.2.1", "memutils": "0.4.3", "vibe-d": "0.7.26", - "libasync": "0.7.5", - "libdparse": "0.2.1" + "hyphenate": "1.1.0", + "libasync": "0.7.5" } } diff --git a/source/ddox/ddoc.d b/source/ddox/ddoc.d index a9b7439d..6697fdc7 100644 --- a/source/ddox/ddoc.d +++ b/source/ddox/ddoc.d @@ -10,6 +10,8 @@ module ddox.ddoc; import vibe.core.log; import vibe.utils.string; +import hyphenate : Hyphenator; + import std.algorithm : canFind, countUntil, map, min, remove; import std.array; import std.conv; @@ -174,6 +176,21 @@ void setOverrideDdocMacroFiles(string[] filenames) } +/** + Enable hyphenation of doc text. +*/ +void enableHyphenation() +{ + s_hyphenator = Hyphenator(import("hyphen.tex")); // en-US + s_enableHyphenation = true; +} + + +void hyphenate(R)(in char[] word, R orng) +{ + s_hyphenator.hyphenate(word, "\­", s => orng.put(s)); +} + /** Holds a DDOC comment and formats it sectionwise as HTML. */ @@ -352,6 +369,8 @@ private { immutable string[string] s_standardMacros; string[string] s_defaultMacros; string[string] s_overrideMacros; + bool s_enableHyphenation; + Hyphenator s_hyphenator; } /// private @@ -514,7 +533,13 @@ private void renderTextLine(R)(ref R dst, string line, DdocContext context) case '_': line = line[1 .. $]; auto ident = skipIdent(line); - if( ident.length ) dst.put(ident); + if( ident.length ) + { + if (s_enableHyphenation && !inCode) + hyphenate(ident, dst); + else + dst.put(ident); + } else dst.put('_'); break; case '.': @@ -545,7 +570,13 @@ private void renderTextLine(R)(ref R dst, string line, DdocContext context) dst.put(ident); if (!inCode) dst.put(""); if( link != "#" ) dst.put(""); - } else dst.put(ident.replace("._", ".")); + } else { + ident = ident.replace("._", "."); + if (s_enableHyphenation && !inCode) + hyphenate(ident, dst); + else + dst.put(ident); + } break; } } diff --git a/source/ddox/main.d b/source/ddox/main.d index f661cc72..7b7944c2 100644 --- a/source/ddox/main.d +++ b/source/ddox/main.d @@ -120,18 +120,20 @@ int setupGeneratorInput(ref string[] args, out GeneratorSettings gensettings, ou MethodStyle file_name_style = MethodStyle.unaltered; SortMode modsort = SortMode.protectionName; SortMode declsort = SortMode.protectionInheritanceName; - bool lowercasenames = false; + bool lowercasenames; + bool hyphenate; getopt(args, //config.passThrough, - "std-macros", ¯ofiles, - "override-macros", &overridemacrofiles, - "navigation-type", &navtype, - "package-order", &pack_order, - "sitemap-url", &sitemapurl, + "decl-sort", &declsort, "file-name-style", &file_name_style, + "hyphenate", &hyphenate, "lowercase-names", &lowercasenames, "module-sort", &modsort, - "decl-sort", &declsort + "navigation-type", &navtype, + "override-macros", &overridemacrofiles, + "package-order", &pack_order, + "sitemap-url", &sitemapurl, + "std-macros", ¯ofiles, ); if (lowercasenames) file_name_style = MethodStyle.lowerCase; @@ -143,6 +145,7 @@ int setupGeneratorInput(ref string[] args, out GeneratorSettings gensettings, ou setDefaultDdocMacroFiles(macrofiles); setOverrideDdocMacroFiles(overridemacrofiles); + if (hyphenate) enableHyphenation(); // parse the json output file auto docsettings = new DdoxSettings; @@ -204,7 +207,7 @@ int cmdFilterDocs(string[] args) if( parent.type != Json.Type.Object || parent.kind.opt!string() != "template" || templateName(parent) != json.name.opt!string() ) return Json.undefined; } - + Protection prot = Protection.Public; if( auto p = "protection" in json ){ switch(p.get!string){ @@ -238,7 +241,7 @@ int cmdFilterDocs(string[] args) return Json.undefined; } } - + if (!keepinternals && is_internal) return Json.undefined; if (!keeputests && is_unittest) return Json.undefined; @@ -351,6 +354,7 @@ Use -h|--help to get detailed usage information for a command. --module-sort=MODE The sort order used for lists of modules --decl-sort=MODE The sort order used for declaration lists --web-file-dir=DIR Make files from dir available on the served site + --hyphenate hyphenate text -h --help Show this help The following values can be used as sorting modes: none, name, protectionName, @@ -378,6 +382,7 @@ protectionInheritanceName --lowercase-names DEPRECATED: Outputs all file names in lower case. This option is useful on case insensitive file systems. + --hyphenate hyphenate text -h --help Show this help The following values can be used as sorting modes: none, name, protectionName,