obsidian-parser 0.1.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c404193f58a335e936da522026f3368b2b7c42d99776fd3910d7667c948a8a54
4
- data.tar.gz: 3b685ae208f985cba65c573f14fa199ea3a40d9f3d392a0103dbc2710178dab1
3
+ metadata.gz: 347ae1e2c1152ccae4ae2ad6a19c4477ae07a8dca77dcfd73d1e31da823cf5f6
4
+ data.tar.gz: 4d2257fd34be583429baf260e3136ca6cdf6cdb4d66fbd592abc396e81a32dfa
5
5
  SHA512:
6
- metadata.gz: 2ab90cafe12e33f2b808f9ad4f4e90617df034ecee71cc1ec5d27b7595767c348f6cad0d52272e3e55b376a902f78b744c080044bc674f981727a1469b6bb08f
7
- data.tar.gz: 6028a69c8f9fd5bdc65df4bdd467b2182492613539c4e4ed373137727b831253b7ee2eb6d6a7b9779aa8555b6764bb1f5644846c65f6393fe373b943c6a952ed
6
+ metadata.gz: 99cfb58610e351574d4ca83faa28b90117ae63a2d219151f005d87e365ee80704d44759c2610cd6bf9b8301fec0ffeb4245d112231fa9ace90202283ad094758
7
+ data.tar.gz: a032cb2063e781db38c5ecafbe13f047d36e16cb5d71cf4c6b8558e40a6867d20b510a25aabbfe2201f5ce45a80a0ca7c729f1c5bd3e78f8030f01be812f61ac
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2023-07-27
4
+
5
+ - Note objects have a `parent` attribute.
6
+
7
+ ## [0.2.0] - 2023-07-24
8
+
9
+ - Note objects have a `content` attribute. Call `content.generate_html` to generate HTML on demand.
10
+
3
11
  ## [0.1.0] - 2023-07-10
4
12
 
5
13
  - Initial release: return a tree of notes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- obsidian-parser (0.1.0)
4
+ obsidian-parser (0.3.0)
5
5
  kramdown (~> 2.4)
6
6
  kramdown-parser-gfm (~> 1.1)
7
7
 
data/README.md CHANGED
@@ -26,6 +26,13 @@ puts parser.index.directories
26
26
  # Index(title: "Projects", slug: "Projects") ]
27
27
  ```
28
28
 
29
+ ### Generating HTML
30
+ ```ruby
31
+ title = note.title
32
+ content = note.content
33
+ content.generate_html
34
+ ```
35
+
29
36
  ## Development
30
37
 
31
38
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -10,6 +10,10 @@ module Obsidian
10
10
  _extract_links(document.root)
11
11
  end
12
12
 
13
+ def to_html
14
+ document.to_html
15
+ end
16
+
13
17
  private
14
18
 
15
19
  attr_reader :document
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Obsidian
4
4
  class Parser
5
- VERSION = "0.1.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -11,12 +11,25 @@ module Obsidian
11
11
  (parent_slug == "") ? title : "#{parent_slug}/#{title}"
12
12
  end
13
13
 
14
+ class MarkdownContent
15
+ def initialize(path)
16
+ @path = path
17
+ end
18
+
19
+ def generate_html
20
+ markdown = @path.read
21
+ Obsidian::ObsidianFlavoredMarkdown.parse(markdown).to_html
22
+ end
23
+ end
24
+
14
25
  class Note
15
- def initialize(title, slug, last_modified)
26
+ def initialize(title, slug, last_modified, content: nil, parent: nil)
16
27
  # TODO: check frontmatter for titles as well
17
28
  @title = title
18
29
  @slug = slug
19
30
  @last_modified = last_modified
31
+ @content = content
32
+ @parent = parent
20
33
  end
21
34
 
22
35
  def inspect
@@ -26,14 +39,17 @@ module Obsidian
26
39
  attr_reader :title
27
40
  attr_reader :slug
28
41
  attr_reader :last_modified
42
+ attr_reader :content
43
+ attr_reader :parent
29
44
  end
30
45
 
31
46
  class Index
32
- def initialize(title = "", slug = "")
47
+ def initialize(title = "", slug = "", content: nil)
33
48
  @title = title
34
49
  @slug = slug
35
50
  @notes = []
36
51
  @directories = {}
52
+ @content = content
37
53
  end
38
54
 
39
55
  def add_directory(title)
@@ -41,12 +57,14 @@ module Obsidian
41
57
  @directories[title] ||= Index.new(title, new_slug)
42
58
  end
43
59
 
44
- def add_note(title, parent_slug, last_modified)
60
+ def add_note(title, parent_slug, last_modified, content: nil)
45
61
  slug = Obsidian.build_slug(title, parent_slug)
46
62
  directory = nested_directory(parent_slug.split("/"))
47
- note = Note.new(title, slug, last_modified)
63
+ note = Note.new(title, slug, last_modified, content: content, parent: directory)
48
64
 
49
65
  directory.notes << note
66
+
67
+ note
50
68
  end
51
69
 
52
70
  def inspect
@@ -60,6 +78,7 @@ module Obsidian
60
78
  attr_reader :notes
61
79
  attr_reader :title
62
80
  attr_reader :slug
81
+ attr_reader :content
63
82
 
64
83
  private
65
84
 
@@ -77,10 +96,14 @@ module Obsidian
77
96
  vault_directory.glob("**/*.md").each do |path|
78
97
  dirname, basename = path.relative_path_from(vault_directory).split
79
98
 
80
- if basename != "index.md" && basename != "."
99
+ next if basename == "."
100
+
101
+ # TODO: handle index.md files
102
+ if basename != "index.md"
81
103
  title = basename.to_s.gsub(/\.md\z/, "")
82
104
  parent_slug = dirname.to_s.gsub(/\A\.\/?/, "")
83
- @index.add_note(title, parent_slug, path.mtime)
105
+ content = MarkdownContent.new(path)
106
+ @index.add_note(title, parent_slug, path.mtime, content: content)
84
107
  end
85
108
  end
86
109
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obsidian-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Moore
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-14 00:00:00.000000000 Z
11
+ date: 2023-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -59,7 +59,6 @@ files:
59
59
  - lib/obsidian/parser/markdown_converter.rb
60
60
  - lib/obsidian/parser/obsidian_flavored_markdown.rb
61
61
  - lib/obsidian/parser/version.rb
62
- - obsidian-parser.gemspec
63
62
  - sig/obsidian/parser.rbs
64
63
  homepage:
65
64
  licenses:
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/obsidian/parser/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "obsidian-parser"
7
- spec.version = Obsidian::Parser::VERSION
8
- spec.authors = ["Mat Moore"]
9
- spec.email = ["matmoore@users.noreply.github.com"]
10
-
11
- spec.summary = "Parse notes created with the Obsidian note-taking tool."
12
- # spec.description = "TODO: Write a longer description or delete this line."
13
-
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.6.0"
16
-
17
- # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
-
19
- spec.metadata["source_code_uri"] = "https://github.com/matmoore/obsidian-parser"
20
- spec.metadata["changelog_uri"] = "https://github.com/matmoore/obsidian-parser/tree/main/CHANGELOG.md"
21
-
22
- # Specify which files should be added to the gem when it is released.
23
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
- spec.files = Dir.chdir(__dir__) do
25
- `git ls-files -z`.split("\x0").reject do |f|
26
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
27
- end
28
- end
29
- spec.bindir = "exe"
30
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
32
-
33
- # Uncomment to register a new dependency of your gem
34
- spec.add_dependency "kramdown", "~> 2.4"
35
- spec.add_dependency "kramdown-parser-gfm", "~> 1.1"
36
-
37
- # For more information and examples about making a new gem, check out our
38
- # guide at: https://bundler.io/guides/creating_gem.html
39
- end