From 0ee118e58706686977b30a41cde053492e5f5ae5 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 8 Feb 2012 14:26:08 -0500 Subject: [PATCH] nitdoc: escape html chars in documentation This is useful for doc block and title stuff. Signed-off-by: Jean Privat --- src/nitdoc.nit | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/nitdoc.nit b/src/nitdoc.nit index cac3298..5543600 100644 --- a/src/nitdoc.nit +++ b/src/nitdoc.nit @@ -299,6 +299,23 @@ class DocContext end redef class String + # Replace all occurence of pattern ith string + fun replace(p: Pattern, string: String): String + do + return self.split_with(p).join(string) + end + + # Escape the following characters < > & and " with their html counterpart + fun html_escape: String + do + var ret = self + if ret.has('&') then ret = ret.replace('&', "&") + if ret.has('<') then ret = ret.replace('<', "<") + if ret.has('>') then ret = ret.replace('>', ">") + if ret.has('"') then ret = ret.replace('"', """) + return ret + end + # Remove "/./", "//" and "bla/../" fun simplify_path: String do @@ -1073,13 +1090,13 @@ redef class ADoc for c in n_comment do res.append(c.text.substring_from(1)) end - return res.to_s + return res.to_s.html_escape end # Oneliner transcription of the doc fun short: String do - return n_comment.first.text.substring_from(1) + return n_comment.first.text.substring_from(1).html_escape end end -- 1.7.9.5