Skip to content
This repository has been archived by the owner on Jul 6, 2021. It is now read-only.

Does it work with python3.6? #1

Open
chriad opened this issue Jun 15, 2018 · 2 comments
Open

Does it work with python3.6? #1

chriad opened this issue Jun 15, 2018 · 2 comments

Comments

@chriad
Copy link

chriad commented Jun 15, 2018

I get the following error (This might be because some things changed in python2 vs. 3?!)

Executed command: "'/home/chriad/.config/nvim/plugged/tagbar-markdown.vim/bin/markdown2ctags.py' -f - --sort=yes '/tmp/nvimbn0LMq/11.md'" Command output: Traceback (most recent call last): File "/home/chriad/.config/nvim/plugged/tagbar-markdown.vim/bin/markdown2ctags.py", line 230, in <module> main() File "/home/chriad/.config/nvim/plugged/tagbar-markdown.vim/bin/markdown2ctags.py", line 220, in main sections = findSections(filename, lines) File "/home/chriad/.config/nvim/plugged/tagbar-markdown.vim/bin/markdown2ctags.py", line 119, in findSections if line.startswith("```"): TypeError: startswith first arg must be bytes or a tuple of bytes, not str Exit code: 1

@tenfyzhong
Copy link
Owner

I tested on python3.6 and everything seems to be working.

@chriad
Copy link
Author

chriad commented Jun 23, 2018

I had to change the following lines to make it work in my environment:

$ git diff bin/markdown2ctags.py
diff --git a/bin/markdown2ctags.py b/bin/markdown2ctags.py
index 71609db..6076679 100755
--- a/bin/markdown2ctags.py
+++ b/bin/markdown2ctags.py
@@ -103,13 +103,16 @@ settextSubjectRe = re.compile(r'^[^\s]+.*$')
 def findParent(previousSections, level):
     parents = filter(lambda s: s is not None,
                      reversed(previousSections[:level]))
-    return parents[0] if parents else None
+    l = list(parents)
+    if l:
+        return l[0]
+    else:
+        return None
 
 
 def findSections(filename, lines):
     sections = []
     inCodeBlock = False
-
     # Initialize previous sections to cope with documents that don't start
     # at the top-most heading type.
     previousSections = [None] * 7
@@ -214,7 +217,7 @@ def main():
         output = open(options.tagfile, 'wb')
 
     for filename in args:
-        f = open(filename, 'rb')
+        f = open(filename, 'r')
         lines = f.read().splitlines()
         f.close()
         sections = findSections(filename, lines)
○ → git diff ftplugin/markdown.vim
diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim
index 581c51a..0b9f1f6 100644
--- a/ftplugin/markdown.vim
+++ b/ftplugin/markdown.vim
@@ -18,7 +18,7 @@ endif
 let g:tagbar_type_markdown = {
             \'ctagstype': 'markdown',
             \ 'ctagsbin' : ctags_bin,
-            \ 'ctagsargs' : '-f - --sort=yes',
+            \ 'ctagsargs' : '-f - --sort=no',
             \ 'kinds' : [
             \     's:sections',
             \     'i:images',

I cannot use the --sort=yes switch because does not know how to compare two Tag objects

$ /home/chriad/.config/nvim/plugged/tagbar-markdown.vim/bin/markdown2ctags.py --sort=yes -f - ./README.md > tags
Traceback (most recent call last):
  File "/home/chriad/.config/nvim/plugged/tagbar-markdown.vim/bin/markdown2ctags.py", line 233, in <module>
    main()
  File "/home/chriad/.config/nvim/plugged/tagbar-markdown.vim/bin/markdown2ctags.py", line 225, in main
    genTagsFile(output, sectionsToTags(sections), sort=options.sort)
  File "/home/chriad/.config/nvim/plugged/tagbar-markdown.vim/bin/markdown2ctags.py", line 179, in genTagsFile
    tags = sorted(tags)
TypeError: '<' not supported between instances of 'Tag' and 'Tag'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants