obsidian-parser 0.1.0 → 0.2.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: 54b2b8b2c841d2c15bf739cc6e2c20a6dea2e29261719104ad1903adbd1a3337
4
+ data.tar.gz: c51dd21ba256fd8c5f03eb646aee741d45167f0cad79eb7ba715c4c776335205
5
5
  SHA512:
6
- metadata.gz: 2ab90cafe12e33f2b808f9ad4f4e90617df034ecee71cc1ec5d27b7595767c348f6cad0d52272e3e55b376a902f78b744c080044bc674f981727a1469b6bb08f
7
- data.tar.gz: 6028a69c8f9fd5bdc65df4bdd467b2182492613539c4e4ed373137727b831253b7ee2eb6d6a7b9779aa8555b6764bb1f5644846c65f6393fe373b943c6a952ed
6
+ metadata.gz: 633e3ccd369bc760f316d977aedf485cef4d76bbe28af3f29079a92d5bcb2b92a6a2d529ea0dcf60c09a85bac2c598838ea70ff51b50b60e372ae33652523cae
7
+ data.tar.gz: 8cac449aa204d036b5e72444afa1235e9dab3cb6b46cd1992d104d6a165775a70171f921c3b3a4064752c5daf08075c20d415a800bc1b6ca6f9c9fcd7c6037b1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2023-07-24
4
+
5
+ - Note objects have a `content` attribute. Call `content.generate_html` to generate HTML on demand.
6
+
3
7
  ## [0.1.0] - 2023-07-10
4
8
 
5
9
  - 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.2.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.2.0"
6
6
  end
7
7
  end
@@ -11,12 +11,24 @@ 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)
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
20
32
  end
21
33
 
22
34
  def inspect
@@ -26,14 +38,16 @@ module Obsidian
26
38
  attr_reader :title
27
39
  attr_reader :slug
28
40
  attr_reader :last_modified
41
+ attr_reader :content
29
42
  end
30
43
 
31
44
  class Index
32
- def initialize(title = "", slug = "")
45
+ def initialize(title = "", slug = "", content: nil)
33
46
  @title = title
34
47
  @slug = slug
35
48
  @notes = []
36
49
  @directories = {}
50
+ @content = content
37
51
  end
38
52
 
39
53
  def add_directory(title)
@@ -41,10 +55,10 @@ module Obsidian
41
55
  @directories[title] ||= Index.new(title, new_slug)
42
56
  end
43
57
 
44
- def add_note(title, parent_slug, last_modified)
58
+ def add_note(title, parent_slug, last_modified, content: nil)
45
59
  slug = Obsidian.build_slug(title, parent_slug)
46
60
  directory = nested_directory(parent_slug.split("/"))
47
- note = Note.new(title, slug, last_modified)
61
+ note = Note.new(title, slug, last_modified, content: content)
48
62
 
49
63
  directory.notes << note
50
64
  end
@@ -60,6 +74,7 @@ module Obsidian
60
74
  attr_reader :notes
61
75
  attr_reader :title
62
76
  attr_reader :slug
77
+ attr_reader :content
63
78
 
64
79
  private
65
80
 
@@ -77,10 +92,14 @@ module Obsidian
77
92
  vault_directory.glob("**/*.md").each do |path|
78
93
  dirname, basename = path.relative_path_from(vault_directory).split
79
94
 
80
- if basename != "index.md" && basename != "."
95
+ next if basename == "."
96
+
97
+ # TODO: handle index.md files
98
+ if basename != "index.md"
81
99
  title = basename.to_s.gsub(/\.md\z/, "")
82
100
  parent_slug = dirname.to_s.gsub(/\A\.\/?/, "")
83
- @index.add_note(title, parent_slug, path.mtime)
101
+ content = MarkdownContent.new(path)
102
+ @index.add_note(title, parent_slug, path.mtime, content: content)
84
103
  end
85
104
  end
86
105
 
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.2.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-24 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