Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lang/markdown/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,21 @@ def markdown_wrap_selection_with_link(url: str):
"""Wraps the selection with a markdown link for the specified url"""
description = actions.edit.selected_text()
actions.user.markdown_insert_link(url, description)

def markdown_insert_table_header(num_columns: int):
"""Creates a table header with the given number of columns"""
if num_columns <= 0:
raise ValueError("Can't insert table header with 0 columns.")
# build a snippet
# add the places to put the column names
snippet_body_parts = ["|"]
for i in range(num_columns):
snippet_body_parts.append(f" ${i + 1} |")
# add the dashed lines
snippet_body_parts.append("\n|")
snippet_body_parts.append("---|" * num_columns)
# put it all together
snippet_body = "".join(snippet_body_parts)
# directly insert the snippet body.
# Because the number of placeholders varies, we could not do this in a .snippet file.
actions.user.insert_snippet(snippet_body)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add a final snippet stop after the separator

In the default snippet backend used outside VS Code, go_to_next_stop_raw() only moves when another stop exists and otherwise clears the stop stack. Because this generated body ends after the separator without a $0 stop, table header one has no saved next stop at all, and for larger tables the final snip next does nothing, leaving the cursor in the last header cell instead of moving past the separator. Append $0 at the end or use the existing final-stop insertion path.

Useful? React with 👍 / 👎.

1 change: 1 addition & 0 deletions lang/markdown/markdown.talon
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ list six:
link: user.insert_snippet_by_name("link")
link clip: user.markdown_insert_link(clip.text())
link wrap clip: user.markdown_wrap_selection_with_link(clip.text())
table header <number_small>: user.markdown_insert_table_header(number_small)