Skip to content

Commit

Permalink
Add support for other languages in code snippet element
Browse files Browse the repository at this point in the history
  • Loading branch information
hunyadi committed Sep 29, 2023
1 parent b2b690a commit a5878c4
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 1 deletion.
55 changes: 54 additions & 1 deletion md2conf/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,83 @@ def elements_from_strings(items: List[str]) -> ET.Element:


_languages = [
"abap",
"actionscript3",
"ada",
"applescript",
"arduino",
"autoit",
"bash",
"csharp",
"c",
"clojure",
"coffeescript",
"coldfusion",
"cpp",
"csharp",
"css",
"cuda",
"d",
"dart",
"delphi",
"diff",
"elixir",
"erlang",
"fortran",
"foxpro",
"go",
"graphql",
"groovy",
"haskell",
"haxe",
"html",
"java",
"javafx",
"javascript",
"json",
"jsx",
"julia",
"kotlin",
"livescript",
"lua",
"mathematica",
"matlab",
"objectivec",
"objectivej",
"ocaml",
"octave",
"pascal",
"perl",
"php",
"powershell",
"prolog",
"puppet",
"python",
"qml",
"r",
"racket",
"rst",
"ruby",
"rust",
"sass",
"scala",
"scheme",
"shell",
"smalltalk",
"splunk",
"sql",
"standardml",
"swift",
"tcl",
"tex",
"tsx",
"typescript",
"vala",
"vb",
"verilog",
"vhdl",
"xml",
"xquery",
"yaml",
]


Expand Down
174 changes: 174 additions & 0 deletions sample/code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<!-- confluence-page-id: 86158409894 -->

If you are a user who wants to publish pages to Confluence, you should install the package [markdown-to-confluence](https://pypi.org/project/markdown-to-confluence/) from PyPI. If you are a developer who wants to contribute, you should clone the repository [md2conf](https://github.com/hunyadi/md2conf) from GitHub.

This document illustrates the [code snippet element](https://support.atlassian.com/confluence-cloud/docs/insert-elements-into-a-page/#Code-snippet) support in Confluence for various languages. The list of languages is not exhaustive.

A language-neutral code block:
```
func:
preformatted text
```

C:
```c
#include <stdio.h>

int main(void)
{
printf("hello, world\n");
}
```
C++:
```cpp
#include <iostream>
int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
```

CSS:
```css
body {
background: #000 url(images/bg.gif) no-repeat left top;
font-family: sans-serif;
}
h1 {
font-weight: bold;
}
```

Go:
```go
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
```

HTML:
```html
<html>
<title>An HTML document</title>
<body>
<p>This <i>is</i> an <b>HTML</b> document.</p>
</body>
</html>
```

Java:
```java
class Simple {
public static void main(String args[]) {
System.out.println("Hello Java!");
}
}
```

JSON:
```json
{
"boolean": true,
"integer": 42,
"string": "value",
"list": [1,2,3]
}
```

Kotlin:
```kotlin
fun main() {
val scope = "World"
println("Hello, $scope!")
}

fun main(args: Array<String>) {
for (arg in args)
println(arg)
}
```

Objective-C:
```objectivec
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
NSLog(@"Hello, World!");
}
return 0;
}
```
Python:
```python
def func(n: int) -> str:
return str(n)
```

Ruby:
```ruby
class MegaGreeter
attr_accessor :names

def initialize(names = "World")
@names = names
end
```

Rust:
```rust
fn main() {
// Print text to the console.
println!("Hello World!");
}
```

Swift:
```swift
class Shape {
var numberOfSides = 0
func simpleDescription() -> String {
return "A shape with \(numberOfSides) sides."
}
}
```

TeX:
```tex
\title{A short \LaTeX Template}
\date{\today}
\documentclass[12pt]{article}
\begin{document}
\maketitle
\section{Introduction}
Correct and improve the following examples of technical writing.
\begin{enumerate}
\item For $n>2\ f(n)=(na+n^2)/(n-1).\ f(2)=2a+4$ for example.\\
\item $a$ is negative so by (1.1)\ $a^2>a$.
\end{enumerate}
\end{document}
```

YAML:
```yaml
--- # The Smiths
- {name: John Smith, age: 33}
- name: Mary Smith
age: 27
- [name, age]: [Rae Smith, 4] # sequences as keys are supported
--- # People, by gender
men: [John Smith, Bill Jones]
women:
- Mary Smith
- Susan Williams
```

0 comments on commit a5878c4

Please sign in to comment.