branch: elpa/subed commit 564b6fec7fddab0b0422ce3d5bba02e3985dd58b Author: Sacha Chua <sa...@sachachua.com> Commit: Sacha Chua <sa...@sachachua.com>
Add preliminary support for comments in VTT files * subed/subed-vtt.el (subed-vtt--regexp-separator): Add support for NOTE. (subed-vtt--jump-to-subtitle-end): Jump before comments. * tests/test-subed-vtt.el ("VTT"): Add test case for comments. --- subed/subed-vtt.el | 6 ++++-- tests/test-subed-vtt.el | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/subed/subed-vtt.el b/subed/subed-vtt.el index 1531e47..6484886 100644 --- a/subed/subed-vtt.el +++ b/subed/subed-vtt.el @@ -44,7 +44,7 @@ ;;; Parsing (defconst subed-vtt--regexp-timestamp "\\(\\([0-9]+\\):\\)?\\([0-9]+\\):\\([0-9]+\\)\\.\\([0-9]+\\)") -(defconst subed-vtt--regexp-separator "\\(?:[[:blank:]]*\n\\)+[[:blank:]]*\n") +(defconst subed-vtt--regexp-separator "\\(?:[[:blank:]]*\n\\)+\\(?:NOTE[ \n]\\(?:.+?\n\\)+\n\\)*\n") (defun subed-vtt--timestamp-to-msecs (time-string) "Find HH:MM:SS.MS pattern in TIME-STRING and convert it to milliseconds. @@ -232,7 +232,9 @@ can be found." ;; `subed-vtt--regexp-separator' here because if subtitle text is empty, ;; it may be the only empty line in the separator, i.e. there's only one ;; "\n". - (let ((regex (concat "\\([[:blank:]]*\n\\)+\\(" subed-vtt--regexp-timestamp "\\)\\|\\([[:blank:]]*\n*\\)\\'"))) + (let ((regex (concat "\\([[:blank:]]*\n\\)+" + "\\(?:NOTE[ \n]\\(?:.+?\n\\)+\n\\)*" + "\\(" subed-vtt--regexp-timestamp "\\)\\|\\([[:blank:]]*\n*\\)\\'"))) (when (re-search-forward regex nil t) (goto-char (match-beginning 0)))) (unless (= (point) orig-point) diff --git a/tests/test-subed-vtt.el b/tests/test-subed-vtt.el index f1ff487..cfcbc93 100644 --- a/tests/test-subed-vtt.el +++ b/tests/test-subed-vtt.el @@ -1151,4 +1151,23 @@ Baz. (describe "Converting msecs to timestamp" (it "uses the right format" (with-temp-vtt-buffer - (expect (subed-msecs-to-timestamp 1401) :to-equal "00:00:01.401"))))) + (expect (subed-msecs-to-timestamp 1401) :to-equal "00:00:01.401")))) + (describe "Working with comments" + (it "ignores the comment when jumping to the end of the subtitle" + (with-temp-vtt-buffer + (insert "WEBVTT + +00:00:00.000 --> 00:00:01.000 +This is a test. + +NOTE A comment can go here +and have more text as needed. + +00:01:00.000 --> 00:00:02.000 +This is another test here. +") + (goto-char (point-min)) + (subed-forward-subtitle-end) + (expect (current-word) :to-equal "test") + (subed-forward-subtitle-end) + (expect (current-word) :to-equal "here")))))