Skip to content

Commit

Permalink
feat(rehype-pretty-code): add new langauges: "VisuAlg" and "Birl"
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfg7 committed Feb 28, 2024
1 parent 2d9a369 commit f5a8a31
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 2 deletions.
29 changes: 27 additions & 2 deletions content/plugin/rehype-pretty-code.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { readFileSync } from 'fs'
import plugin, { Options } from 'rehype-pretty-code'
import { getHighlighter } from 'shiki'

const options: Partial<Options> = {
theme: {
Expand All @@ -11,8 +13,31 @@ const options: Partial<Options> = {
if (node.children.length === 0) {
node.children = [{ type: 'text', value: ' ' }]
}
}
// Feel free to add classNames that suit your docs
},
getHighlighter: options =>
getHighlighter({
...options,
langs: [
() =>
JSON.parse(
readFileSync(
'./content/plugin/rehype-pretty-code/visualg.tmLanguage.json',
'utf-8'
)
),
() =>
JSON.parse(
readFileSync(
'./content/plugin/rehype-pretty-code/birl.tmLanguage.json',
'utf-8'
)
)
],
langAlias: {
visualg: 'VisuAlg',
birl: 'BIRL'
}
})
}

const rehypePrettyCode = [plugin, options]
Expand Down
60 changes: 60 additions & 0 deletions content/plugin/rehype-pretty-code/birl.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "BIRL",
"scopeName": "source.birl",
"patterns": [
{ "include": "#keywords" },
{ "include": "#functions" },
{ "include": "#constants" },
{ "include": "#numbers" },
{ "include": "#logical" },
{ "include": "#types" },
{ "include": "#comments" },
{ "include": "#arithmetic" },
{ "include": "#assignments" },
{ "include": "#comparison" },
{ "include": "#strings" },
{ "include": "#storages" },
{ "include": "#identifiers" }
],
"repository": {
"keywords": {
"patterns": [{
"name": "keyword.control.birl",
"match": "\\b(HORA DO SHOW|ELE QUE A GENTE QUER?|NAO VAI DAR NAO|QUE NAO VAI DAR O QUE?|VAMO MONSTRO|SAI FILHO DA PUTA|MAIS QUERO MAIS|AJUDA O MALUCO TA DOENTE|NEGATIVA BAMBAM|BORA CUMPADE|BIRL|OH O HOME AI PO|CE QUER VER ESSA PORRA?|FRANGO|MONSTRINHO|MONSTRO|MONSTRAO|TRAPEZIO|TRAPEZIO DESCENDENTE|BICEPS)\\b"
}]
}
},
"identifiers": {
"patterns": [
{
"name": "entity.other.attribute-name",
"match": "(\\b(super)\\b)|#[_a-zA-Z0-9]+"
},
{
"name": "entity.name.function",
"match": "((?<=classe\\s)|(?<=herda\\s))([_a-zA-Z0-9]+)"
},
{
"name": "entity.name.function",
"match": "([_a-zA-Z0-9]+)(?=[ ]*[=][ ]*(\\(|funcao))"
},
{
"name": "variable.parameter",
"match": "([_a-zA-Z0-9]+)(?=[ ]*[=])"
},
{
"name": "entity.other.attribute-name",
"match": "([_a-zA-Z0-9]+)(?=[ ]*[:])"
},
{
"name": "entity.name.function",
"match": "([_a-zA-Z0-9]+)(?=([\\s]*\\())"
},
{
"name": "variable.language",
"match": "[_a-zA-Z0-9]+"
}
]
}
}
110 changes: 110 additions & 0 deletions content/plugin/rehype-pretty-code/visualg.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "VisuAlg",
"scopeName": "source.visualg",
"patterns": [
{ "include": "#keywords" },
{ "include": "#functions" },
{ "include": "#constants" },
{ "include": "#numbers" },
{ "include": "#logical" },
{ "include": "#types" },
{ "include": "#comments" },
{ "include": "#arithmetic" },
{ "include": "#assignments" },
{ "include": "#comparison" },
{ "include": "#strings" },
{ "include": "#storages" },
{ "include": "#identifiers" }
],
"repository": {
"keywords": {
"patterns": [
{
"name": "keyword.control.visualg",
"match": "(?i)\\b(ate|até|algoritmo|faca|faça|var|inicio|fimalgoritmo|se|senao|senão|fimse|para|fimpara|fazer|enquanto|escolha|caso|padrao|repita|tente|pegue|procedimento|fimprocedimento|finalmente|retorne|funcao|fimfuncao|função|fimfunção|escreva|leia)\\b"
}
]
},
"comments": {
"patterns": [
{
"match": "(//).*",
"name": "comment.line.double-slash"
}
]
},
"constants": {
"patterns": [
{
"name": "constant.language.visualg",
"match": "(?i)\\b(falso|verdadeiro)\\b"
}
]
},
"functions": {
"patterns": [{
"name": "keyword.function.visualg",
"match": "\\b(escreva|escreval|leia)\\b"
}]
},
"identifiers": {
"patterns": [
{
"name": "entity.other.attribute-name",
"match": "(\\b(super)\\b)|#[_a-zA-Z0-9]+"
},
{
"name": "entity.name.function",
"match": "((?<=classe\\s)|(?<=herda\\s))([_a-zA-Z0-9]+)"
},
{
"name": "entity.name.function",
"match": "([_a-zA-Z0-9]+)(?=[ ]*[=][ ]*(\\(|funcao))"
},
{
"name": "variable.parameter",
"match": "([_a-zA-Z0-9]+)(?=[ ]*[=])"
},
{
"name": "entity.other.attribute-name",
"match": "([_a-zA-Z0-9]+)(?=[ ]*[:])"
},
{
"name": "entity.name.function",
"match": "([_a-zA-Z0-9]+)(?=([\\s]*\\())"
},
{
"name": "variable.language",
"match": "[_a-zA-Z0-9]+"
}
]
},
"strings": {
"patterns": [
{
"name": "string.quoted.single.visualg",
"begin": "\\'",
"end": "\\'",
"patterns": [
{
"name": "constant.character.escape.visualg",
"match": "\\\\."
}
]
},
{
"name": "string.quoted.double.visualg",
"begin": "\"",
"end": "\"",
"patterns": [
{
"name": "constant.character.escape.visualg",
"match": "\\\\."
}
]
}
]
}
}
}
40 changes: 40 additions & 0 deletions content/posts/draft-post/draft-post.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,46 @@ const sum: (x: number) => number = foo
const y: number = sum(1)
```

Portugol VisualG (show line numbers) {/* https://github.com/DesignLiquido/delegua */}

```visualg showLineNumbers
algoritimo "Idade"
// Disciplina : Programação Estruturada
// Professor : Adjenor Cristiano
// Descrição : Determina se o usuário é maior de idade ou não
// Autor(a) : Mateus Felipe Gonçalves <[email protected]>
// Data atual : 23/02/2024
var
idade: inteiro
inicio
escreval("Sua idade")
escreva("-> ")
leia(idade)
escreval("")
se (idade >= 18) entao
escreva("Maior de idade")
senao
escreva("Menor de idade")
fimse
escreval("")
fimalgoritimo
```

Birl {/* https://github.com/DesignLiquido/delegua */}

```birl
HORA DO SHOW
FRANGO FR = 'a';
CE QUER VER ESSA PORRA? ("Hello, World! Porra!\n");
BORA CUMPADE 0;
BIRL
```

Rust

```rust title="Simple Rust code with title"
Expand Down

0 comments on commit f5a8a31

Please sign in to comment.