summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2021-03-05 08:11:32 +0100
committerAnthon van der Neut <anthon@mnt.org>2021-03-05 08:11:32 +0100
commit1c31c7f46cfbc1f363c793f7bdf42c9f5fa239c6 (patch)
treeedc414926de0c4611dcf875a00ab37d5254203f8
parent4f1ad1c392bd557405e9901c5b8750d12a4f1260 (diff)
downloadruamel.yaml-1c31c7f46cfbc1f363c793f7bdf42c9f5fa239c6.tar.gz
fix #371
-rw-r--r--comments.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/comments.py b/comments.py
index a091d37..13a519e 100644
--- a/comments.py
+++ b/comments.py
@@ -230,7 +230,10 @@ class CommentedBase(object):
comment = comment[:-1] # strip final newline if there
start_mark = CommentMark(indent)
for com in comment.split('\n'):
- pre_comments.append(CommentToken('# ' + com + '\n', start_mark, None))
+ c = com.strip()
+ if len(c) > 0 and c[0] != '#':
+ com = '# ' + com
+ pre_comments.append(CommentToken(com + '\n', start_mark, None))
def yaml_set_comment_before_after_key(
self, key, before=None, indent=0, after=None, after_indent=None