Skip to content

Commit

Permalink
Add support for the Go language
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Jun 30, 2024
1 parent 42a48e8 commit 7dc9ea2
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Jupytext works with notebooks in any of the following languages:
- Coconut
- F#
- Gnuplot
- Go
- Groovy
- Haskell
- IDL
Expand Down
1 change: 1 addition & 0 deletions src/jupytext/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"comment_suffix": "*/",
},
".xsh": {"language": "xonsh", "comment": "#"},
".go": {"language": "go", "comment": "//"},
}

_COMMENT_CHARS = [
Expand Down
100 changes: 100 additions & 0 deletions tests/data/notebooks/inputs/ipynb_go/hello_world_gonb.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "8795db3a-af9a-4f03-a68d-019330861b54",
"metadata": {},
"source": [
"A notebook that use [GoNB](https://github.com/janpfeifer/gonb)"
]
},
{
"cell_type": "markdown",
"id": "50a2fb21-01b3-46d0-9951-f9a1301a85ca",
"metadata": {},
"source": [
"the code below comes from [tutorial.ipynb](https://github.com/janpfeifer/gonb/blob/main/examples/tutorial.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "75d8418d-a918-4cc8-b42e-384db01f21ae",
"metadata": {},
"outputs": [],
"source": [
"func main() {\n",
" fmt.Printf(\"Hello World!\")\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3620f46f-efd5-4454-bc29-418297012ce9",
"metadata": {},
"outputs": [],
"source": [
"%%\n",
"fmt.Printf(\"Hello World!\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "82f4bb1f-3311-4fca-8025-c54c0305dc64",
"metadata": {},
"outputs": [],
"source": [
"import \"github.com/janpfeifer/gonb/gonbui\"\n",
"\n",
"%%\n",
"gonbui.DisplayHtml(`<span style=\"background:pink; color:#111; border-radius: 3px; border: 3px solid orange; font-size: 18px;\">I 🧡 GoNB!</span>`)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1a5584ff-f346-45cf-95c1-a3e3b7146c6c",
"metadata": {},
"outputs": [],
"source": [
"%%\n",
"gonbui.DisplayMarkdown(\"#### Objective\\n\\n1. Have fun coding **Go**;\\n1. Profit...\\n\"+\n",
" `$$f(x) = \\int_{-\\infty}^{\\infty} e^{-x^2} dx$$`)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "de996381-d92c-4ce6-a135-50cf39288aa1",
"metadata": {},
"outputs": [],
"source": [
"func init_a() {\n",
" fmt.Println(\"init_a\")\n",
"}\n",
"%%\n",
"fmt.Println(\"main\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Go (gonb)",
"language": "go",
"name": "gonb"
},
"language_info": {
"codemirror_mode": "",
"file_extension": ".go",
"mimetype": "",
"name": "go",
"nbconvert_exporter": "",
"pygments_lexer": "",
"version": "go1.21.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
42 changes: 42 additions & 0 deletions tests/data/notebooks/outputs/ipynb_to_Rmd/hello_world_gonb.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
jupyter:
kernelspec:
display_name: Go (gonb)
language: go
name: gonb
---

A notebook that use [GoNB](https://github.com/janpfeifer/gonb)


the code below comes from [tutorial.ipynb](https://github.com/janpfeifer/gonb/blob/main/examples/tutorial.ipynb)

```{go}
func main() {
fmt.Printf("Hello World!")
}
```

```{go}
fmt.Printf("Hello World!")
```

```{go}
import "github.com/janpfeifer/gonb/gonbui"
%%
gonbui.DisplayHtml(`<span style="background:pink; color:#111; border-radius: 3px; border: 3px solid orange; font-size: 18px;">I 🧡 GoNB!</span>`)
```

```{go}
gonbui.DisplayMarkdown("#### Objective\n\n1. Have fun coding **Go**;\n1. Profit...\n"+
`$$f(x) = \int_{-\infty}^{\infty} e^{-x^2} dx$$`)
```

```{go}
func init_a() {
fmt.Println("init_a")
}
%%
fmt.Println("main")
```
41 changes: 41 additions & 0 deletions tests/data/notebooks/outputs/ipynb_to_hydrogen/hello_world_gonb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// -*- coding: utf-8 -*-
// ---
// jupyter:
// kernelspec:
// display_name: Go (gonb)
// language: go
// name: gonb
// ---

// %% [markdown]
// A notebook that use [GoNB](https://github.com/janpfeifer/gonb)

// %% [markdown]
// the code below comes from [tutorial.ipynb](https://github.com/janpfeifer/gonb/blob/main/examples/tutorial.ipynb)

// %%
func main() {
fmt.Printf("Hello World!")
}

// %%
%%
fmt.Printf("Hello World!")

// %%
import "github.com/janpfeifer/gonb/gonbui"

%%
gonbui.DisplayHtml(`<span style="background:pink; color:#111; border-radius: 3px; border: 3px solid orange; font-size: 18px;">I 🧡 GoNB!</span>`)

// %%
%%
gonbui.DisplayMarkdown("#### Objective\n\n1. Have fun coding **Go**;\n1. Profit...\n"+
`$$f(x) = \int_{-\infty}^{\infty} e^{-x^2} dx$$`)

// %%
func init_a() {
fmt.Println("init_a")
}
%%
fmt.Println("main")
42 changes: 42 additions & 0 deletions tests/data/notebooks/outputs/ipynb_to_md/hello_world_gonb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
jupyter:
kernelspec:
display_name: Go (gonb)
language: go
name: gonb
---

A notebook that use [GoNB](https://github.com/janpfeifer/gonb)


the code below comes from [tutorial.ipynb](https://github.com/janpfeifer/gonb/blob/main/examples/tutorial.ipynb)

```go
func main() {
fmt.Printf("Hello World!")
}
```

```go
fmt.Printf("Hello World!")
```

```go
import "github.com/janpfeifer/gonb/gonbui"

%%
gonbui.DisplayHtml(`<span style="background:pink; color:#111; border-radius: 3px; border: 3px solid orange; font-size: 18px;">I 🧡 GoNB!</span>`)
```

```go
gonbui.DisplayMarkdown("#### Objective\n\n1. Have fun coding **Go**;\n1. Profit...\n"+
`$$f(x) = \int_{-\infty}^{\infty} e^{-x^2} dx$$`)
```

```go
func init_a() {
fmt.Println("init_a")
}
%%
fmt.Println("main")
```
44 changes: 44 additions & 0 deletions tests/data/notebooks/outputs/ipynb_to_myst/hello_world_gonb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
kernelspec:
display_name: Go (gonb)
language: go
name: gonb
---

A notebook that use [GoNB](https://github.com/janpfeifer/gonb)

+++

the code below comes from [tutorial.ipynb](https://github.com/janpfeifer/gonb/blob/main/examples/tutorial.ipynb)

```{code-cell}
func main() {
fmt.Printf("Hello World!")
}
```

```{code-cell}
%%
fmt.Printf("Hello World!")
```

```{code-cell}
import "github.com/janpfeifer/gonb/gonbui"
%%
gonbui.DisplayHtml(`<span style="background:pink; color:#111; border-radius: 3px; border: 3px solid orange; font-size: 18px;">I 🧡 GoNB!</span>`)
```

```{code-cell}
%%
gonbui.DisplayMarkdown("#### Objective\n\n1. Have fun coding **Go**;\n1. Profit...\n"+
`$$f(x) = \int_{-\infty}^{\infty} e^{-x^2} dx$$`)
```

```{code-cell}
func init_a() {
fmt.Println("init_a")
}
%%
fmt.Println("main")
```
39 changes: 39 additions & 0 deletions tests/data/notebooks/outputs/ipynb_to_percent/hello_world_gonb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// -*- coding: utf-8 -*-
// ---
// jupyter:
// kernelspec:
// display_name: Go (gonb)
// language: go
// name: gonb
// ---

// %% [markdown]
// A notebook that use [GoNB](https://github.com/janpfeifer/gonb)

// %% [markdown]
// the code below comes from [tutorial.ipynb](https://github.com/janpfeifer/gonb/blob/main/examples/tutorial.ipynb)

// %%
func main() {
fmt.Printf("Hello World!")
}

// %%
fmt.Printf("Hello World!")

// %%
import "github.com/janpfeifer/gonb/gonbui"

%%
gonbui.DisplayHtml(`<span style="background:pink; color:#111; border-radius: 3px; border: 3px solid orange; font-size: 18px;">I 🧡 GoNB!</span>`)

// %%
gonbui.DisplayMarkdown("#### Objective\n\n1. Have fun coding **Go**;\n1. Profit...\n"+
`$$f(x) = \int_{-\infty}^{\infty} e^{-x^2} dx$$`)

// %%
func init_a() {
fmt.Println("init_a")
}
%%
fmt.Println("main")
34 changes: 34 additions & 0 deletions tests/data/notebooks/outputs/ipynb_to_script/hello_world_gonb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// -*- coding: utf-8 -*-
// ---
// jupyter:
// kernelspec:
// display_name: Go (gonb)
// language: go
// name: gonb
// ---

// A notebook that use [GoNB](https://github.com/janpfeifer/gonb)

// the code below comes from [tutorial.ipynb](https://github.com/janpfeifer/gonb/blob/main/examples/tutorial.ipynb)

func main() {
fmt.Printf("Hello World!")
}

fmt.Printf("Hello World!")

// +
import "github.com/janpfeifer/gonb/gonbui"

%%
gonbui.DisplayHtml(`<span style="background:pink; color:#111; border-radius: 3px; border: 3px solid orange; font-size: 18px;">I 🧡 GoNB!</span>`)
// -

gonbui.DisplayMarkdown("#### Objective\n\n1. Have fun coding **Go**;\n1. Profit...\n"+
`$$f(x) = \int_{-\infty}^{\infty} e^{-x^2} dx$$`)

func init_a() {
fmt.Println("init_a")
}
%%
fmt.Println("main")

0 comments on commit 7dc9ea2

Please sign in to comment.