From 2975da255dd1c9f244f314885af8fb84c9f3fe54 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sat, 5 Nov 2016 01:02:26 +0000 Subject: [PATCH] Enforce blank lines before code blocks. Helps a little with #66. --- racer.el | 9 +++++++++ test/racer-test.el | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/racer.el b/racer.el index f286c56..c75005c 100644 --- a/racer.el +++ b/racer.el @@ -403,7 +403,16 @@ the user to choose." (setq current-section-lines nil)) ;; If this is an opening ``` ((s-starts-with-p "```" line) + ;; Ensure we have a blank line in the previous text. + ;; This is primarily a workaround for https://github.com/phildawes/racer/issues/646 + ;; but it's prettier too. (funcall finish-text-section) + (when sections + ;; Ensure the previous section ends with a blank line. + (let ((previous-section (car sections))) + (unless (s-ends-with-p "\n" previous-section) + (setf (car sections) + (concat previous-section "\n"))))) (setq in-code t)) ;; Headings ((and (not in-code) (s-starts-with-p "# " line)) diff --git a/test/racer-test.el b/test/racer-test.el index fee5ba6..3086baf 100644 --- a/test/racer-test.el +++ b/test/racer-test.el @@ -84,6 +84,24 @@ struct Foo {} " #[derive(Debug)] struct Foo {}"))) +(ert-deftest racer--propertize-docstring-code-newlines () + "Ensure we always have a blank line before a code block." + + (should + (equal + (racer--remove-properties + (racer--propertize-docstring "```bar() +``` +foo +``` +bar(); +```")) + " bar(); + +foo + + bar();"))) + (ert-deftest racer--propertize-docstring-newlines () "Ensure we still handle links that have been split over two lines." (should