fix comment formatting regression from safe markup
authorIan Kelling <ian@iankelling.org>
Tue, 4 Oct 2016 07:37:00 +0000 (00:37 -0700)
committerIan Kelling <ian@iankelling.org>
Tue, 4 Oct 2016 17:09:01 +0000 (10:09 -0700)
_site/cgi/comment
b.rb
comments/blog/site-redesign.html/1475551365.0383508 [new file with mode: 0755]
css/main.scss
get-comments
iank-mod.el
setup.sh

index 4b14c3c7c7bd9c3dfa9337a8494656913f662917..b84c45ebe6076132bf81a39b0cb1da5d3820eb00 100755 (executable)
@@ -142,6 +142,10 @@ if COMMENT_TXT.length > 1000 or GOTO.length > 150
   fail('length of comment or goto is too great')
 end
 
+if COMMENT_TXT.length <= 2 or COMMENT_TXT =~ /\A\s*\Z/
+  fail('not enough content in comment')
+end
+
 
 captchad = false
 if cgi.has_key?('answer') && cgi.has_key?('question')
@@ -300,7 +304,7 @@ $db.execute('insert into c values (NULL, ?, ?, ?, ?, ?)',
              COMMENT_TXT])
 
 if date
-  new_count = $db.execute(query + 'and date > ?',date)
+  new_count = $db.execute(query + 'and date > ?', date)
 else
   new_count = $db.execute(query)
 end
@@ -328,7 +332,7 @@ END_OF_MESSAGE
       smtp.send_message msg, opts[:from], opts[:to]
     end
   end
-  send_email :subject => 'new comments on iankelling.org'
+  send_email :subject => "new comment on #{DN}"
 end
 
 post(md_file)
diff --git a/b.rb b/b.rb
index 2dc8ad8ad7d9287dda1106a67b66544642663cd0..c2dbc75bae6ff6f8b5839941f083e7ef19e49563 100644 (file)
--- a/b.rb
+++ b/b.rb
@@ -125,15 +125,14 @@ EOF
   end
 
   def comment_html(comment, date)
-    inner = Redcarpet::Markdown.new(Redcarpet::Render::Safe, fenced_code_blocks: true).render(<<EOF)
-#{comment}
-<span class="comment-date">#{Time.at(date).strftime("%b %-d '%y")}</span>
-EOF
     # I tried putting the time,  %I:%M %p UTC, but it looks kinda
     # clunky, going against my simple theme.
+    user_input = Redcarpet::Markdown.new(Redcarpet::Render::Safe,
+                                   fenced_code_blocks: true).render(comment)
     <<EOF
 <div class="comment">
-  #{inner}
+  #{user_input}
+  <p class="comment-date">#{Time.at(date).strftime("%b %-d '%y")}</p>
 </div>
 EOF
   end
diff --git a/comments/blog/site-redesign.html/1475551365.0383508 b/comments/blog/site-redesign.html/1475551365.0383508
new file mode 100755 (executable)
index 0000000..3f2cca6
--- /dev/null
@@ -0,0 +1 @@
+Sample comment with *formatting*.
\ No newline at end of file
index c8782244dce4d7ce26395af972b6695bd22fe3db..7c7e4a23206f6754d978c9f3fcb84538fa20b9d1 100644 (file)
@@ -80,16 +80,10 @@ body {
   line-height: 1.5; // default is too scrunched
 }
 
-// alternative to a <br>. whatever.
-// https://stackoverflow.com/questions/7363766/how-to-insert-a-line-break-before-an-element-using-css
-.comment-date::before {
-  content: "\A";
-}
-
 .comment-date {
   color: $comment-date-color;
   font-size: 15px;
-  white-space: pre;
+  margin-top: 0;
 }
 
 .post-date {
index 54ea99a6a28e504ecb27e8b6bfc94316e96bd5be..071031976b3fb6f9895d45d6929ac756ae94a5b8 100755 (executable)
@@ -24,7 +24,7 @@ shell="ssh $(chost iankelling.org)"
 while [[ $1 ]]; do
     case $1 in
         -a) all=true; shift ;;
-        -l) shell= ; shift ;; # -l  for local
+        -l) shell= ; shift ;; # -l  for local site instead of iankelling.org
     esac
 done
 
index 4faea5f958d70d4d42953584745fa74325db9b5b..b033cbc27f3d2efa009e7f7a0e262ad227bbf1a6 100644 (file)
 ;; You should have received a copy of the GNU General Public License
 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-(defun iankmod-start ()
-  (interactive)
-  (shell-command "/a/h/get-comments" "*messages*")
-  (find-file "/tmp/hcomments")
-  (iankmod 1))
+
+;; generally, use m-x iankmod-start. c-u to run on local testing
+;; instance.  Alternatively, run get-comments with whatever args,
+;; manually open /tmp/hcomments, then run (iankmod).
+
+(defun iankmod-start (arg)
+  (interactive "P")
+  (setq iankmod-last-arg (if (equal arg '(4)) " -l" ""))
+  (let ((cmd (concat "/a/h/get-comments" iankmod-last-arg)))
+    (shell-command cmd "*messages*")
+    (find-file "/tmp/hcomments")
+    (iankmod 1)))
+
 (defun iankmod-save ()
   (interactive)
-  (shell-command "/a/h/set-comments" "*messages*"))
+  (basic-save-buffer)
+  (let ((cmd (concat "/a/h/set-comments" iankmod-last-arg)))
+    (shell-command cmd "*messages*")))
 
 
 (defun iankmod-set-state (state)
index deb61b9c26e6e3bf0613e0fcc791fbf805b00cf6..cfcee75694c4bf7e014d12471292b3775e6815de 100755 (executable)
--- a/setup.sh
+++ b/setup.sh
@@ -29,6 +29,7 @@ gitroot=/a/bin/githtml
 shopt -s extglob
 
 type -P a2enmod &>/dev/null || pi apache2
+type -P sqlite3 &>/dev/null || pi sqlite3
 
 acme-tiny-wrapper $domain