Skip to content

Commit

Permalink
https://github.com/cristianvasquez/obsidian-prettify/issues/22
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianvasquez committed Dec 30, 2020
1 parent 7cf7404 commit 2f310a7
Show file tree
Hide file tree
Showing 14 changed files with 414 additions and 79 deletions.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,31 @@ The default hotkey is `Ctrl+Alt+L`.

## Examples

### Add a frontmatter
### Hashtags janitor

Say you have:

```markdown

A #new and #exciting paragraph!
```

After 'Update fields':

```markdown
---
tags:
- '#new'
- '#exciting'

---

A #new and #exciting paragraph!


```

### Update values in the frontmatter

Before:

Expand Down Expand Up @@ -133,6 +157,11 @@ unzip ~/Downloads/obsidian-prettify-0.1.zip -d $OBSIDIAN_VAULT_DIR/.obsidian/plu

## Version History

### v.0.0.7

- New Refactor tags functionality (ctrl+shift+o)
- Can add emoticons as tags

### v.0.0.6

Fixed frontmatter bug
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"author": "Cristian",
"authorUrl": "https://github.com/cristianvasquez",
"js": "main.js",
"version": "0.0.6"
"version": "0.0.7"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"remark-images": "^2.0.0",
"remark-parse": "^9.0.0",
"unified": "^9.2.0",
"js-yaml": "git://github.com/nodeca/js-yaml.git#dev"
"js-yaml": "git://github.com/nodeca/js-yaml.git#dev",
"zwitch": "^1.0.5"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^15.1.0",
Expand Down
97 changes: 97 additions & 0 deletions src/__tests__/__snapshots__/frontmatter.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Add quotes 1`] = `
VFile {
"contents": "---
Name:
- '#Hello'
- World
- ' #Hi'
- '#with/tab'
- '#with/tab/teb/tib'
- '#howdy_bla'
- '#howdy-bla'
Other tag: '#Nothing'
tags:
- '#Nothing'
date updated: '2010-06-10T00:20:00+02:00'
---
Outside frontmatter
#tag
",
"cwd": "/home/cvasquez/obsidian/workspace/.obsidian/plugins/markdown-prettifier",
"data": Object {},
"history": Array [],
"messages": Array [],
}
`;

exports[`Adds tags 1`] = `
VFile {
"contents": "---
Name:
- '#Hi'
date updated: '2010-06-10T00:20:00+02:00'
tags:
- '#hello'
- '#world'
---
",
"cwd": "/home/cvasquez/obsidian/workspace/.obsidian/plugins/markdown-prettifier",
"data": Object {},
"history": Array [],
"messages": Array [],
}
`;

exports[`Creates a header 1`] = `
VFile {
"contents": "---
Expand Down Expand Up @@ -84,6 +132,40 @@ perhaps 1% ? of the humans use it for facts?
}
`;

exports[`Preserve previous tags 1`] = `
VFile {
"contents": "---
tags:
- '#preserve_me'
- '#hello'
- '#world'
date updated: '2010-06-10T00:20:00+02:00'
---
",
"cwd": "/home/cvasquez/obsidian/workspace/.obsidian/plugins/markdown-prettifier",
"data": Object {},
"history": Array [],
"messages": Array [],
}
`;

exports[`Preserve previous tags 2`] = `
VFile {
"contents": "---
date updated: '2010-06-10T00:20:00+02:00'
tags:
- '#literatura'
---
",
"cwd": "/home/cvasquez/obsidian/workspace/.obsidian/plugins/markdown-prettifier",
"data": Object {},
"history": Array [],
"messages": Array [],
}
`;

exports[`Respects emojis 1`] = `
VFile {
"contents": "---
Expand Down Expand Up @@ -115,3 +197,18 @@ date updated: '2010-06-10T00:20:00+02:00'
"messages": Array [],
}
`;

exports[`add quote 1`] = `
VFile {
"contents": "---
tag: '#hello'
date updated: '{{date:YYYY-MM-DDTHH:mm:ssZ}}'
---
",
"cwd": "/home/cvasquez/obsidian/workspace/.obsidian/plugins/markdown-prettifier",
"data": Object {},
"history": Array [],
"messages": Array [],
}
`;
124 changes: 100 additions & 24 deletions src/__tests__/frontmatter.spec.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
const prettifier = require('../prettifier')
const moment =require ('moment')
const moment = require('moment')
const fixed_date = moment('2010-06-09T15:20:00-07:00')


test("Does not create a header", () => {
const content = `No Header`
return prettifier(content, {
createHeaderIfNotPresent: false,
moment:fixed_date
}).then(data => {
return prettifier(content, {createHeaderIfNotPresent: false}, {}, {today: fixed_date}).then(data => {
expect(data).toMatchSnapshot();
});
});

test("Creates a header", () => {
const content = `No Header`
return prettifier(content, {
createHeaderIfNotPresent: true,
currentMoment:fixed_date
}).then(data => {
return prettifier(content,
{
createHeaderIfNotPresent: true
}, {today: fixed_date}
).then(data => {
expect(data).toMatchSnapshot();
});
});

test("Creates date first time", () => {
const content = `No Header`
return prettifier(content, {
createHeaderIfNotPresent: true,
updateHeader: false,
currentMoment:fixed_date
}).then(data => {
return prettifier(content,
{
createHeaderIfNotPresent: true,
updateHeader: false,
}, {today: fixed_date}).then(data => {
expect(data).toMatchSnapshot();
});
});
Expand All @@ -41,8 +39,7 @@ date updated: '1999-06-10T00:20:00+02:00'
---`
return prettifier(content, {
updateHeader: false,
moment:fixed_date
}).then(data => {
}, {today: fixed_date}).then(data => {
expect(data).toMatchSnapshot();
});
});
Expand All @@ -63,9 +60,8 @@ In their own language, with their own model of the world.
perhaps 1% ? of the humans use it for facts?
`
return prettifier(content, {
currentMoment:fixed_date
}).then(data => {
return prettifier(content, {}
, {today: fixed_date}).then(data => {
expect(data).toMatchSnapshot();
});
});
Expand All @@ -76,9 +72,8 @@ test("Respects hash", () => {
tag: '#Interpretability'
---
`
return prettifier(content, {
currentMoment:fixed_date
}).then(data => {
return prettifier(content, {},
{today: fixed_date}).then(data => {
expect(data).toMatchSnapshot();
});
});
Expand All @@ -89,9 +84,90 @@ tag: '#🦐'
---
🦐
`
return prettifier(content, {
currentMoment:fixed_date
return prettifier(content, {}, {today: fixed_date}).then(data => {
expect(data).toMatchSnapshot();
});
});


test("add quote", () => {
const content = `---
tag: #hello
---
`
return prettifier(content, {}, {
frontMatterData: {}
}).then(data => {
expect(data).toMatchSnapshot();
});
});

it("Add quotes", () => {
const content = `---
Name:
- #Hello
- World
- ' #Hi'
- #with/tab
- #with/tab/teb/tib
- #howdy_bla
- #howdy-bla
Other tag: #Nothing
tags: #Nothing
---
Outside frontmatter
#tag
`;
return prettifier(content, {}, {today: fixed_date}).then(data => {
expect(data).toMatchSnapshot();
});
});


it("Adds tags", () => {
const content = `---
Name:
- #Hi
---
`;
return prettifier(content,
{}, {today: fixed_date, tags: ['#hello', '#world']}).then(data => {
expect(data).toMatchSnapshot();
});
});

it("Preserve previous tags", () => {
const content = `---
tags:
- #preserve_me
---
`;
return prettifier(content,
{}, {today: fixed_date, tags: ['#hello', '#world']}).then(data => {
expect(data).toMatchSnapshot();
});
});



it("Preserve previous tags", () => {
const content = `---
date updated: '2020-12-09T00:14:06+01:00'
tags: '#literatura'
---
`
return prettifier(content,
{}, {today: fixed_date, tags: []}).then(data => {
expect(data).toMatchSnapshot();
});
});

15 changes: 15 additions & 0 deletions src/__tests__/template.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,18 @@ Name: 🦐
const data = template.replace(input, one_day_in_the_past)
expect(data).toBe(expectedOuput);
});


it("Finds hashtags", () => {
const input = `
## Hello
#ble
#bla_bla####
#ble\Blu
#ble/bla/blo #blex#blix
#
`;

const data = template.findHashtags(input)
expect(data).toEqual(['#ble', '#bla_bla####', '#bleBlu', '#ble/bla/blo', '#blex#blix']);
});

0 comments on commit 2f310a7

Please sign in to comment.