diff options
Diffstat (limited to 'mod')
-rw-r--r-- | mod/mod-package-details.cxx | 8 | ||||
-rw-r--r-- | mod/mod-package-version-details.cxx | 8 | ||||
-rw-r--r-- | mod/page.cxx | 19 | ||||
-rw-r--r-- | mod/page.hxx | 9 |
4 files changed, 41 insertions, 3 deletions
diff --git a/mod/mod-package-details.cxx b/mod/mod-package-details.cxx index fa073b5..5074eca 100644 --- a/mod/mod-package-details.cxx +++ b/mod/mod-package-details.cxx @@ -189,9 +189,15 @@ handle (request& rq, response& rs) const string what (name.string () + " description"); s << (full - ? DIV_TEXT (*d, *pkg->description_type, id, what, error) + ? DIV_TEXT (*d, + *pkg->description_type, + true /* strip_title */, + id, + what, + error) : DIV_TEXT (*d, *pkg->description_type, + true /* strip_title */, options_->package_description (), url (!full, squery, page, id), id, diff --git a/mod/mod-package-version-details.cxx b/mod/mod-package-version-details.cxx index 82221b4..40cbad6 100644 --- a/mod/mod-package-version-details.cxx +++ b/mod/mod-package-version-details.cxx @@ -187,9 +187,15 @@ handle (request& rq, response& rs) const string what (title + " description"); s << (full - ? DIV_TEXT (*d, *pkg->description_type, id, what, error) + ? DIV_TEXT (*d, * + pkg->description_type, + true /* strip_title */, + id, + what, + error) : DIV_TEXT (*d, *pkg->description_type, + true /* strip_title */, options_->package_description (), url (!full, id), id, diff --git a/mod/page.cxx b/mod/page.cxx index 63bb495..228a137 100644 --- a/mod/page.cxx +++ b/mod/page.cxx @@ -933,6 +933,21 @@ namespace brep cmark_parser_finish (parser.get ()), [] (cmark_node* n) {cmark_node_free (n);}); + // Strip the document "title". + // + if (strip_title_) + { + cmark_node* child (cmark_node_first_child (doc.get ())); + + if (child != nullptr && + cmark_node_get_type (child) == CMARK_NODE_HEADING && + cmark_node_get_heading_level (child) == 1) + { + cmark_node_unlink (child); + cmark_node_free (child); + } + } + // Render the AST into an XHTML fragment. // // Note that unlike GitHub we follow the default API behavior and @@ -973,7 +988,9 @@ namespace brep s.resume_indentation (); if (f.truncated) - s << DIV(CLASS="more") << A(HREF=*url_) << "More" << ~A << ~DIV; + s << DIV(CLASS="more") + << "... " << A(HREF=*url_) << "More" << ~A + << ~DIV; s << ~DIV; } diff --git a/mod/page.hxx b/mod/page.hxx index 1138a80..7260031 100644 --- a/mod/page.hxx +++ b/mod/page.hxx @@ -589,6 +589,10 @@ namespace brep // description element instead. Note that such an error indicates an issue // with the implementation, rather than with the specified text. // + // Optionally strip the heuristically detected document "title". Currently, + // this only applies to Markdown where a leading level-one heading is + // assumed to be the title. + // class DIV_TEXT { public: @@ -596,11 +600,13 @@ namespace brep // DIV_TEXT (const string& t, text_type tp, + bool st, const string& id, const string& what, const basic_mark& diag) : text_ (t), type_ (tp), + strip_title_ (st), length_ (t.size ()), url_ (nullptr), id_ (id), @@ -613,6 +619,7 @@ namespace brep // DIV_TEXT (const string& t, text_type tp, + bool st, size_t l, const string& u, const string& id, @@ -620,6 +627,7 @@ namespace brep const basic_mark& diag) : text_ (t), type_ (tp), + strip_title_ (st), length_ (l), url_ (&u), id_ (id), @@ -634,6 +642,7 @@ namespace brep private: const string& text_; text_type type_; + bool strip_title_; size_t length_; const string* url_; // Full page url. string id_; |