diff --git a/lang/markdown/markdown.py b/lang/markdown/markdown.py index bee199824..b049c6227 100644 --- a/lang/markdown/markdown.py +++ b/lang/markdown/markdown.py @@ -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) diff --git a/lang/markdown/markdown.talon b/lang/markdown/markdown.talon index d297416bf..e378286d3 100644 --- a/lang/markdown/markdown.talon +++ b/lang/markdown/markdown.talon @@ -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 : user.markdown_insert_table_header(number_small)