Skip to content

Commit

Permalink
fix: Removed text as the default language selector for code blocks (#355
Browse files Browse the repository at this point in the history
)
  • Loading branch information
shd101wyy authored Mar 18, 2024
1 parent 28704eb commit 5254777
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: 'Install nodejs 18'
- name: 'Install nodejs 20'
uses: actions/setup-node@v3
with:
node-version: '18'
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: 'Install nodejs 18'
- name: 'Install nodejs 20'
uses: actions/setup-node@v2
with:
node-version: '18'
node-version: '20'
- name: 'Build and test'
run: |
corepack enable
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/typedoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: 'Install nodejs 18'
- name: 'Install nodejs 20'
uses: actions/setup-node@v2
with:
node-version: '18'
node-version: '20'
- name: 'Build and test'
run: |
corepack enable
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ Please visit https://github.com/shd101wyy/vscode-markdown-preview-enhanced/relea

## [Unreleased]

## [0.9.9] - 2024-03-11

### Bug fixes

- Fixed [Long sidebarToc does not display completely](https://github.com/shd101wyy/crossnote/pull/354) by @moonlitusun
- Removed the `text` as the default language selector for code block.

### Chore

- Updated [flake.nix](./flake.nix) and node.js to 20.

## [0.9.8] - 2024-03-10

### New features
Expand Down
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/nixos-23.05";
url = "github:NixOS/nixpkgs/nixos-23.11";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils = { url = "github:numtide/flake-utils"; };
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crossnote",
"version": "0.9.8",
"version": "0.9.9",
"description": "A powerful markdown notebook tool",
"keywords": [
"markdown"
Expand Down
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
mkShell {
buildInputs = [ nodejs_18 yarn ];
buildInputs = [ nodejs_20 yarn ];
shellHook = ''
# ...
'';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/block-info/parse-block-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const parseBlockInfo = (raw = ''): BlockInfo => {

const classNames = attributes.class ? attributes.class.split(/\s+/) : [];
if (!language) {
language = classNames[0] || 'text';
language = classNames[0] || '';
}
if (!classNames.includes(language)) {
attributes.class = [language, ...classNames].join(' ');
Expand Down
2 changes: 1 addition & 1 deletion src/render-enhancers/code-block-styling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default async function enhance($: CheerioStatic): Promise<void> {
$container.empty().append($(`<code></code>`).text(code));
}

$container.addClass(`language-${language}`);
$container.addClass(`language-${language || 'text'}`);
if (info.attributes['class']) {
$container.addClass(info.attributes['class']);
addLineNumbersIfNecessary($container, code);
Expand Down
10 changes: 5 additions & 5 deletions test/lib/block-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const testCasesForParseBlockInfo: {
}[] = [
{
input: '',
expect: { language: 'text', attributes: { class: 'text' } },
expect: { language: '', attributes: { class: '' } },
},
{
input: '{}',
expect: { language: 'text', attributes: { class: 'text' } },
expect: { language: '', attributes: { class: '' } },
},
{
input: '{#id}',
expect: { language: 'text', attributes: { id: 'id', class: 'text' } },
expect: { language: '', attributes: { id: 'id', class: '' } },
},
{
input: 'js cmd=true',
Expand Down Expand Up @@ -78,8 +78,8 @@ const testCasesForParseBlockInfo: {
{
input: ' {just=attribute}',
expect: {
language: 'text',
attributes: { just: 'attribute', class: 'text' },
language: '',
attributes: { just: 'attribute', class: '' },
},
},
{
Expand Down
19 changes: 19 additions & 0 deletions test/markdown/test-files/test8.expect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Code blocks {#code-blocks data-source-line="1"}

``` {data-source-line="3"}
This is code block without language selector
```

```text {data-source-line="7"}
This is another text code block
```

``` {.python data-source-line="11"}
def hello():
println("Hello, world")
```

```python {data-source-line="16"}
def hello():
println("Hello, world")
```
19 changes: 19 additions & 0 deletions test/markdown/test-files/test8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Code blocks

```
This is code block without language selector
```

```text
This is another text code block
```

```{.python}
def hello():
println("Hello, world")
```

```python
def hello():
println("Hello, world")
```

0 comments on commit 5254777

Please sign in to comment.