@hyvor/design 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +1,7 @@
1
1
  <script>import "./prism.scss";
2
2
  export let code;
3
3
  export let language = "html";
4
- import Prism from "prismjs";
5
- import "prism-svelte";
6
- function getCode() {
7
- let ret = code;
8
- ret = ret.replace(/^[^\S\r\n]*\n/, "");
9
- ret = ret.replace(/\n[^\S\r\n]*$/, "");
10
- let lines = ret.split("\n");
11
- let indent = null;
12
- lines = lines.map((line) => {
13
- if (indent === null) {
14
- const match = line.match(/^(\s*)/);
15
- indent = match ? match[1].length : 0;
16
- }
17
- if (line.substring(0, indent).trim() !== "") {
18
- return line;
19
- }
20
- line = line.substring(indent);
21
- return line;
22
- });
23
- ret = lines.join("\n");
24
- return Prism.highlight(ret, Prism.languages[language], language);
25
- }
4
+ import getCode from "./prism.js";
26
5
  </script>
27
6
 
28
- <pre class="language-{language}"><code>{@html getCode()}</code></pre>
7
+ <pre class="language-{language}"><code>{@html getCode(code, language)}</code></pre>
@@ -1,6 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  import './prism.scss';
3
- import 'prism-svelte';
4
3
  declare const __propDef: {
5
4
  props: {
6
5
  code: string;
@@ -0,0 +1,2 @@
1
+ import 'prism-svelte';
2
+ export default function getCode(code: string, language: string): string;
@@ -0,0 +1,26 @@
1
+ import Prism from 'prismjs';
2
+ import 'prism-svelte';
3
+ export default function getCode(code, language) {
4
+ let ret = code;
5
+ // remove the first empty line
6
+ ret = ret.replace(/^[^\S\r\n]*\n/, "");
7
+ // remove the last empty line
8
+ ret = ret.replace(/\n[^\S\r\n]*$/, "");
9
+ let lines = ret.split("\n");
10
+ let indent = null; // number of spaces to remove from each line
11
+ lines = lines.map(line => {
12
+ if (indent === null) {
13
+ // find the indent
14
+ const match = line.match(/^(\s*)/);
15
+ indent = match ? match[1].length : 0;
16
+ }
17
+ if (line.substring(0, indent).trim() !== "") {
18
+ return line;
19
+ }
20
+ // remove the indent
21
+ line = line.substring(indent);
22
+ return line;
23
+ });
24
+ ret = lines.join("\n");
25
+ return Prism.highlight(ret, Prism.languages[language], language);
26
+ }
package/dist/index.css CHANGED
@@ -13,6 +13,8 @@
13
13
  body {
14
14
  background-color: var(--background, var(--accent-lightest));
15
15
  color: var(--text);
16
+ margin: 0;
17
+ padding: 0;
16
18
  }
17
19
 
18
20
  button, a {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyvor/design",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "scripts": {
@@ -35,6 +35,7 @@
35
35
  "@sveltejs/adapter-static": "^2.0.3",
36
36
  "@sveltejs/kit": "^1.25.1",
37
37
  "@sveltejs/package": "^2.0.0",
38
+ "@types/prismjs": "^1.26.1",
38
39
  "prismjs": "^1.29.0",
39
40
  "publint": "^0.1.9",
40
41
  "sass": "^1.68.0",