Hello,
There is a plugin named "markdown_index" in vscode, which can add number to the title of markdown file. Is therealready a similar plugin for this function in cuda?
Thanks!
plugin like VSCode's Markdown Index
-
- Posts: 2265
- Joined: 25.08.2021 18:15
Re: plugin for markdown index
there is not.
it is not very hard to create this plugin, if one reads the code-tree contents and handles it.
it is not very hard to create this plugin, if one reads the code-tree contents and handles it.
Re: plugin for markdown index
Thanks the advise! I used to think to use formatter to do this. Dose any API to read the code tree content directly?main Alexey wrote: ↑04.01.2024 06:01 there is not.
it is not very hard to create this plugin, if one reads the code-tree contents and handles it.
-
- Posts: 2265
- Joined: 25.08.2021 18:15
Re: plugin for markdown index
API to read code-tree
- app_proc() with PROC_GET_CODETREE: Returns int handle of built-in code-tree UI control. Use tree_proc() to work with it.
- tree_proc() with new ID of code-tree with action TREE_ITEM_ENUM_EX: Enumerates subitems of given item. Pass item = 0 for root tree item.
- again tree_proc() with action TREE_ITEM_GET_RANGE: Should be used only for code-tree. Returns range, stored in tree-item, as 4-tuple (start_x, start_y, end_x, end_y). If range is not set, returns (-1,-1,-1,-1).
- app_proc() with PROC_GET_CODETREE: Returns int handle of built-in code-tree UI control. Use tree_proc() to work with it.
- tree_proc() with new ID of code-tree with action TREE_ITEM_ENUM_EX: Enumerates subitems of given item. Pass item = 0 for root tree item.
- again tree_proc() with action TREE_ITEM_GET_RANGE: Should be used only for code-tree. Returns range, stored in tree-item, as 4-tuple (start_x, start_y, end_x, end_y). If range is not set, returns (-1,-1,-1,-1).
Re: plugin for markdown index
Trying it, when sub_item is true, how to get the id of subitems and then to get the range of subitem by TREE_ITEM_GET_RANGE ?main Alexey wrote: ↑04.01.2024 06:48 API to read code-tree
- app_proc() with PROC_GET_CODETREE: Returns int handle of built-in code-tree UI control. Use tree_proc() to work with it.
- tree_proc() with new ID of code-tree with action TREE_ITEM_ENUM_EX: Enumerates subitems of given item. Pass item = 0 for root tree item.
- again tree_proc() with action TREE_ITEM_GET_RANGE: Should be used only for code-tree. Returns range, stored in tree-item, as 4-tuple (start_x, start_y, end_x, end_y). If range is not set, returns (-1,-1,-1,-1).
{'id': 748213568, 'text': '2023.12.28', 'data': '', 'img': -1, 'sub_items': True}
-
- Posts: 2265
- Joined: 25.08.2021 18:15
Re: plugin for markdown index
Step 1
>>> ct=app_proc(PROC_GET_CODETREE,'')
>>> ct
140556715678064
Step 2
>>> =tree_proc(ct, TREE_ITEM_ENUM_EX, id_item=0)
[{'id': 140556582911424, 'text': 'log', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582911584, 'text': 'get_color', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582911744, 'text': 'load_config', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582911904, 'text': 'Command', 'data': '', 'img': 1, 'sub_items': True}]
Here we get only last tree-node with 'sub_items'. it is node 'Command' for my python file.
I copy its ID 140556582911904 and pass it to param "id_item":
Step 3
>>> =tree_proc(ct, TREE_ITEM_ENUM_EX, id_item=140556582911904)
[{'id': 140556582912064, 'text': '__init__', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582912224, 'text': 'config', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582912384, 'text': 'on_change_slow', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582912544, 'text': 'on_lexer', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582912704, 'text': 'on_lexer_parsed', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582912864, 'text': 'on_scroll', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582913184, 'text': 'by_timer', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582913344, 'text': 'on_focus', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582913504, 'text': 'work', 'data': '', 'img': 5, 'sub_items': False}]
Step 4
I copy id of last item (caption 'work' under node 'Command') and get its code-tree range
>>> =tree_proc(ct, TREE_ITEM_GET_RANGE, id_item=140556582913504)
(4, 102, 21, 180)
>>> ct=app_proc(PROC_GET_CODETREE,'')
>>> ct
140556715678064
Step 2
>>> =tree_proc(ct, TREE_ITEM_ENUM_EX, id_item=0)
[{'id': 140556582911424, 'text': 'log', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582911584, 'text': 'get_color', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582911744, 'text': 'load_config', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582911904, 'text': 'Command', 'data': '', 'img': 1, 'sub_items': True}]
Here we get only last tree-node with 'sub_items'. it is node 'Command' for my python file.
I copy its ID 140556582911904 and pass it to param "id_item":
Step 3
>>> =tree_proc(ct, TREE_ITEM_ENUM_EX, id_item=140556582911904)
[{'id': 140556582912064, 'text': '__init__', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582912224, 'text': 'config', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582912384, 'text': 'on_change_slow', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582912544, 'text': 'on_lexer', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582912704, 'text': 'on_lexer_parsed', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582912864, 'text': 'on_scroll', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582913184, 'text': 'by_timer', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582913344, 'text': 'on_focus', 'data': '', 'img': 5, 'sub_items': False}, {'id': 140556582913504, 'text': 'work', 'data': '', 'img': 5, 'sub_items': False}]
Step 4
I copy id of last item (caption 'work' under node 'Command') and get its code-tree range
>>> =tree_proc(ct, TREE_ITEM_GET_RANGE, id_item=140556582913504)
(4, 102, 21, 180)
Re: plugin for markdown index
Get it, that would be easy to add the number.
Thanks a lot!
Thanks a lot!
-
- Posts: 2265
- Joined: 25.08.2021 18:15
Re: plugin for markdown index
if you share the resulting 'markdown index' code, i can add it to plugin 'Markdown Editing'.
Re: plugin for markdown index
I made a plugin for this, the code is attached. I think using recursive methods may make the code more clean, but I am not very familiar with it. So I just used 6 layers of loops. The code is not very Pythonic, but it works. If you want, you can modify or add it to the plugin. I am very happy to make contributions to Curatext.main Alexey wrote: ↑05.01.2024 08:21 if you share the resulting 'markdown index' code, i can add it to plugin 'Markdown Editing'.
- Attachments
-
- add_index.rar
- (768 Bytes) Downloaded 156 times
-
- Posts: 2265
- Joined: 25.08.2021 18:15
Re: plugin for markdown index
Merged new code to 'Markdown Editing' plugin as a new command in 'Plugins / Markdown Editing'; thanks.