Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use YAML for extra fields? #5

Open
mrswats opened this issue Aug 22, 2021 · 5 comments
Open

how to use YAML for extra fields? #5

mrswats opened this issue Aug 22, 2021 · 5 comments

Comments

@mrswats
Copy link

mrswats commented Aug 22, 2021

In the readme you mention something about embedded yaml and extra fields, but I cannot see anything documented about it. How does it work? What do I need? I would love to have more data in my database instead of having to alter the generated database directly.

I love this tool, thank you!

@jgranduel
Copy link

Hi,
if I may, as I've just discovered this tool, do you mean something like described in pandoc documentation and reported in this short example?

file : a.md, containing embedded YAML for title, author, etc.

---
title: Test title
date: 2021-08-23
author:
    - Bob
    - Alice
    - And and some other authors
some_key: |
    and some very
    long multiline
    value.
tree_value:
    sub_tree : 
        - foo
        - bar
        - baz 
---

# title

## subtitle 1 

para 1.

## subtitle 2

para 2.

then

> markdown-to-sqlite.exe md.sqlite markdown_table a.md
.schema
CREATE TABLE [markdown_table] (
   [_id] TEXT PRIMARY KEY,
   [_path] TEXT,
   [text] TEXT,
   [html] TEXT,
   [title] TEXT,
   [date] TEXT,
   [author] TEXT,
   [some_key] TEXT,
   [tree_value] TEXT
);
.mode line
select * from markdown_table;
      _id = 5d48a79a3e66a0b67d03c582501493d256004f1f
     _path = a.md
      text = # title

## subtitle 1

para 1.

## subtitle 2

para 2.
      html = <h1>title</h1>
<h2>subtitle 1</h2>
<p>para 1.</p>
<h2>subtitle 2</h2>
<p>para 2.</p>
     title = Test title
      date = 2021-08-23
    author = ["Bob", "Alice", "And and some other authors"]
  some_key = and some very
long multiline
value.

tree_value = {"sub_tree": ["foo", "bar", "baz"]}

yaml metadata are serialized as JSON.

HTH

@mrswats
Copy link
Author

mrswats commented Aug 23, 2021

Yeah, pretty much this is what I was not getting, many thanks!

It wasn't clear to me how I could: First, embed YAML into the markdown, and second, what would the result of this would be. It wouldn't have occurred to me to look at the Pandoc documentation!

This all makes a lot more sense now.

@mrswats
Copy link
Author

mrswats commented Aug 23, 2021

Would it be worth it to open a PR to add this information in the README?

@jgranduel
Copy link

Happy I could help you.
AFAIK, metadata block should be terminated by --- but not ... as pandoc allows.

By the way, have you come across this post or SQLite documentation for automatically extracting data from json which is pretty relevant here. I changed the previous SQLite schema:

SQLite> alter table markdown_table add column extra_info generated always as (json_extract(tree_value, '$.extra_info')) virtual;

I created another markdown (b.md):

---
title: Test 2
date: 2021-08-23
author:
    - me
    - etc
some_key: |
    and some very
    long multiline
    value.
tree_value:
    extra_info: 
        "I am an extra info!"
---

# title b

## subtitle b  

para b.
> markdown-to-sqlite.exe md.sqlite markdown_table b.md

then sqlite3 md.sqlite (note the extra_info column):

sqlite>.mode line
sqlite> select * from markdown_table where title = 'Test 2';
       _id = bb801cb4e571ec0bc7a6ad6d316dacf27c7b107a
     _path = b.md
      text = # title b

## subtitle b

para b.
      html = <h1>title b</h1>
<h2>subtitle b</h2>
<p>para b.</p>
     title = Test 2
      date = 2021-08-23
    author = ["me", "etc"]
  some_key = and some very
long multiline
value.

tree_value = {"extra_info": "I am an extra info!"}
extra_info = I am an extra info!

And all the thanks to Simon Willison!

@mrswats
Copy link
Author

mrswats commented Aug 23, 2021

Opened #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants