From 7c96369a753f98c6995eb3a1cca871986694f85e Mon Sep 17 00:00:00 2001 From: shishitao Date: Fri, 11 Mar 2022 21:21:38 -0600 Subject: [PATCH] add Tcl as a supported language --- docs/languages.md | 1 + jupytext/languages.py | 2 + tests/notebooks/ipynb_tcl/tcl_test.ipynb | 86 +++++++++++++++++++ .../mirror/ipynb_to_Rmd/tcl_test.Rmd | 26 ++++++ .../mirror/ipynb_to_hydrogen/tcl_test.tcl | 24 ++++++ .../notebooks/mirror/ipynb_to_md/tcl_test.md | 26 ++++++ .../mirror/ipynb_to_myst/tcl_test.md | 25 ++++++ .../mirror/ipynb_to_percent/tcl_test.tcl | 24 ++++++ .../mirror/ipynb_to_script/tcl_test.tcl | 20 +++++ 9 files changed, 234 insertions(+) create mode 100644 tests/notebooks/ipynb_tcl/tcl_test.ipynb create mode 100644 tests/notebooks/mirror/ipynb_to_Rmd/tcl_test.Rmd create mode 100644 tests/notebooks/mirror/ipynb_to_hydrogen/tcl_test.tcl create mode 100644 tests/notebooks/mirror/ipynb_to_md/tcl_test.md create mode 100644 tests/notebooks/mirror/ipynb_to_myst/tcl_test.md create mode 100644 tests/notebooks/mirror/ipynb_to_percent/tcl_test.tcl create mode 100644 tests/notebooks/mirror/ipynb_to_script/tcl_test.tcl diff --git a/docs/languages.md b/docs/languages.md index f6de536c7..592cf3a13 100644 --- a/docs/languages.md +++ b/docs/languages.md @@ -28,5 +28,6 @@ Jupytext works with notebooks in any of the following languages: - Script of Script - TypeScript - Haskell +- Tcl Extending Jupytext to more languages should be easy, see the sections on [contributing to](contributing.md) and [developing](developing.md) Jupytext. diff --git a/jupytext/languages.py b/jupytext/languages.py index b205dc65a..5be600066 100644 --- a/jupytext/languages.py +++ b/jupytext/languages.py @@ -27,6 +27,7 @@ "sql", "cython", "haskell", + "tcl", ] # Supported file extensions (and languages) @@ -65,6 +66,7 @@ "comment_suffix": "*)", }, # OCaml only has block comments ".hs": {"language": "haskell", "comment": "--"}, + ".tcl": {"language": "tcl", "comment": "#"}, } _COMMENT_CHARS = [ diff --git a/tests/notebooks/ipynb_tcl/tcl_test.ipynb b/tests/notebooks/ipynb_tcl/tcl_test.ipynb new file mode 100644 index 000000000..078e988de --- /dev/null +++ b/tests/notebooks/ipynb_tcl/tcl_test.ipynb @@ -0,0 +1,86 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Assign Values" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a = 1\n" + ] + } + ], + "source": [ + "set a 1\n", + "puts \"a = $a\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Loop" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I inside first loop: 0\n", + "I inside first loop: 1\n", + "I inside first loop: 2\n", + "I inside first loop: 3\n", + "I inside first loop: 4\n", + "I inside first loop: 5\n", + "I inside first loop: 6\n", + "I inside first loop: 7\n", + "I inside first loop: 8\n", + "I inside first loop: 9\n" + ] + } + ], + "source": [ + "for {set i 0} {$i < 10} {incr i} {\n", + " puts \"I inside first loop: $i\"\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Tcl", + "language": "tcl", + "name": "tcljupyter" + }, + "language_info": { + "file_extension": ".tcl", + "mimetype": "txt/x-tcl", + "name": "tcl", + "version": "8.6.11" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/tests/notebooks/mirror/ipynb_to_Rmd/tcl_test.Rmd b/tests/notebooks/mirror/ipynb_to_Rmd/tcl_test.Rmd new file mode 100644 index 000000000..2d1159736 --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_Rmd/tcl_test.Rmd @@ -0,0 +1,26 @@ +--- +jupyter: + kernelspec: + display_name: Tcl + language: tcl + name: tcljupyter +--- + +# Assign Values + +```{tcl} +set a 1 +puts "a = $a" +``` + +# Loop + +```{tcl} +for {set i 0} {$i < 10} {incr i} { + puts "I inside first loop: $i" +} +``` + +```{tcl} + +``` diff --git a/tests/notebooks/mirror/ipynb_to_hydrogen/tcl_test.tcl b/tests/notebooks/mirror/ipynb_to_hydrogen/tcl_test.tcl new file mode 100644 index 000000000..f05500e76 --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_hydrogen/tcl_test.tcl @@ -0,0 +1,24 @@ +# --- +# jupyter: +# kernelspec: +# display_name: Tcl +# language: tcl +# name: tcljupyter +# --- + +# %% [markdown] +# # Assign Values + +# %% +set a 1 +puts "a = $a" + +# %% [markdown] +# # Loop + +# %% +for {set i 0} {$i < 10} {incr i} { + puts "I inside first loop: $i" +} + +# %% diff --git a/tests/notebooks/mirror/ipynb_to_md/tcl_test.md b/tests/notebooks/mirror/ipynb_to_md/tcl_test.md new file mode 100644 index 000000000..68b2589d4 --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_md/tcl_test.md @@ -0,0 +1,26 @@ +--- +jupyter: + kernelspec: + display_name: Tcl + language: tcl + name: tcljupyter +--- + +# Assign Values + +```tcl +set a 1 +puts "a = $a" +``` + +# Loop + +```tcl +for {set i 0} {$i < 10} {incr i} { + puts "I inside first loop: $i" +} +``` + +```tcl + +``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/tcl_test.md b/tests/notebooks/mirror/ipynb_to_myst/tcl_test.md new file mode 100644 index 000000000..a5744e730 --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_myst/tcl_test.md @@ -0,0 +1,25 @@ +--- +kernelspec: + display_name: Tcl + language: tcl + name: tcljupyter +--- + +# Assign Values + +```{code-cell} +set a 1 +puts "a = $a" +``` + +# Loop + +```{code-cell} +for {set i 0} {$i < 10} {incr i} { + puts "I inside first loop: $i" +} +``` + +```{code-cell} + +``` diff --git a/tests/notebooks/mirror/ipynb_to_percent/tcl_test.tcl b/tests/notebooks/mirror/ipynb_to_percent/tcl_test.tcl new file mode 100644 index 000000000..f05500e76 --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_percent/tcl_test.tcl @@ -0,0 +1,24 @@ +# --- +# jupyter: +# kernelspec: +# display_name: Tcl +# language: tcl +# name: tcljupyter +# --- + +# %% [markdown] +# # Assign Values + +# %% +set a 1 +puts "a = $a" + +# %% [markdown] +# # Loop + +# %% +for {set i 0} {$i < 10} {incr i} { + puts "I inside first loop: $i" +} + +# %% diff --git a/tests/notebooks/mirror/ipynb_to_script/tcl_test.tcl b/tests/notebooks/mirror/ipynb_to_script/tcl_test.tcl new file mode 100644 index 000000000..8b1b0025b --- /dev/null +++ b/tests/notebooks/mirror/ipynb_to_script/tcl_test.tcl @@ -0,0 +1,20 @@ +# --- +# jupyter: +# kernelspec: +# display_name: Tcl +# language: tcl +# name: tcljupyter +# --- + +# # Assign Values + +set a 1 +puts "a = $a" + +# # Loop + +for {set i 0} {$i < 10} {incr i} { + puts "I inside first loop: $i" +} + +