jekyll-euclid 0.1.0 → 0.1.1

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: 743add07e4ef9648d4b86ee1ad3a4a4878d1cf2f72b268c316cc36d523a9eefe
4
- data.tar.gz: 67d1cc710682a731d44f9a6d5a9f7cfeb46a9b0af00bda434c873df7f11cf471
3
+ metadata.gz: d62ac5ec85a146f9c437ed9783b973b80940b33a8560dfb5dbc308211bac6f6b
4
+ data.tar.gz: 428a7a1023cf327802fb54f98b5185e14dfbf7742e2441a2d980d560b8228067
5
5
  SHA512:
6
- metadata.gz: 198f52f27b9e9d46df571a923fc5db49e92c0c003fcf2f5cb379fb09ccd8c2eda4c850df2f3e5ecad2031657f8cb69a5ee5b8a4bea66acc958c87af2b6215c11
7
- data.tar.gz: 9c438ee3d1a503c88da8e45bd3ed60188e7906faeaffc16b1ccd4050f1e620ea192ec2e544b3633d07ba6e761d8044829cf82cf8197598630741568fcacf677c
6
+ metadata.gz: 74c27c31dade1be4085fbcfb85ba23db375c2062ee68645a5812f659b1653a86ea0a71c85ccbf336466c3f646ac25cc6a043ae89f77d9d4df6cc6daef7c24413
7
+ data.tar.gz: f44be22c330e5f8428fc1ebb50ec6b525497789fc085f6eba84e046d867dc5d5166f3835ad66731d2948d3d1583478b4f1459b257076a913d1b8f7fe8d690899
data/.rubocop.yml CHANGED
@@ -6,3 +6,6 @@ Style/StringLiterals:
6
6
 
7
7
  Style/StringLiteralsInInterpolation:
8
8
  EnforcedStyle: double_quotes
9
+
10
+ Naming/FileName:
11
+ Enabled: false
@@ -1,67 +1,70 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module Converters
5
+ # Converts .euclid files, which are a custom format for writing mathematical proofs based on latex math environments
3
6
  class EuclidConverter < Converter
4
7
  safe true
5
8
  priority :highest
6
-
9
+
7
10
  def matches(ext)
8
11
  ext =~ /^\.euclid$/i
9
12
  end
10
-
11
- def output_ext(ext)
13
+
14
+ def output_ext(_)
12
15
  ".html"
13
16
  end
14
-
17
+
15
18
  def replace_theorem(content)
16
19
  @theorem_counter += 1
17
-
20
+
18
21
  "**Theorem #{@theorem_counter}:** *#{content[8..-6].strip}*"
19
22
  end
20
-
23
+
21
24
  def replace_lemma(content)
22
25
  @theorem_counter += 1
23
-
26
+
24
27
  "**Lemma #{@theorem_counter}:** *#{content[6..-6].strip}*"
25
28
  end
26
-
29
+
27
30
  def replace_corollary(content)
28
31
  @corollary_counter += 1
29
-
32
+
30
33
  "**Corollary #{@theorem_counter}.#{@corollary_counter}:** *#{content[10..-6].strip}*"
31
34
  end
32
-
35
+
33
36
  def replace_axiom(content)
34
37
  @axiom_counter += 1
35
-
38
+
36
39
  "**Axiom #{@axiom_counter}:** *#{content[6..-6].strip}*"
37
40
  end
38
-
41
+
39
42
  def replace_definition(content)
40
43
  @definition_counter += 1
41
-
44
+
42
45
  "**Definition #{@definition_counter}:** *#{content[11..-6].strip}*"
43
46
  end
44
-
47
+
45
48
  def replace_proof(content)
46
49
  "*Proof.* #{content[7..-6]}"
47
50
  end
48
-
51
+
49
52
  def get_term_index(content)
50
- theorem_index = content.index("\\theorem") || 999999
51
- lemma_index = content.index("\\lemma") || 999999
52
- corollary_index = content.index("\\corollary") || 999999
53
-
53
+ theorem_index = content.index("\\theorem") || 999_999
54
+ lemma_index = content.index("\\lemma") || 999_999
55
+ corollary_index = content.index("\\corollary") || 999_999
56
+
54
57
  if theorem_index < lemma_index && theorem_index < corollary_index
55
58
  return theorem_index, "\\theorem"
56
59
  elsif lemma_index < corollary_index
57
60
  return lemma_index, "\\lemma"
58
- elsif corollary_index < 999999
61
+ elsif corollary_index < 999_999
59
62
  return corollary_index, "\\corollary"
60
63
  end
61
-
62
- return -1, nil
64
+
65
+ [-1, nil]
63
66
  end
64
-
67
+
65
68
  def replace_theorem_terms(content, term)
66
69
  case term
67
70
  when "\\theorem"
@@ -72,76 +75,72 @@ module Jekyll
72
75
  replace_corollary(content)
73
76
  end
74
77
  end
75
-
78
+
76
79
  def replace_theorems(content)
77
80
  @theorem_counter = 0
78
-
81
+
79
82
  term_index, term = get_term_index(content)
80
-
81
- if term != "\\corollary"
82
- @corollary_counter = 0
83
- end
84
-
85
- end_index = content[term_index..-1].index("\\end") + term_index
86
-
87
- while term_index > 0
83
+
84
+ term != "\\corollary" && @corollary_counter = 0
85
+
86
+ end_index = content[term_index..].index("\\end") + term_index
87
+
88
+ while term_index.positive?
88
89
  term_content = content[term_index..(end_index + 3)]
89
- content = content[0..(term_index - 1)] + replace_theorem_terms(term_content, term) + content[(end_index + 4)..-1]
90
-
90
+ content_before = content[0..(term_index - 1)]
91
+ content_after = content[(end_index + 4)..]
92
+ content = content_before + replace_theorem_terms(term_content, term) + content_after
93
+
91
94
  term_index, term = get_term_index(content)
92
-
93
- if term_index == -1
94
- break
95
- end
96
-
97
- end_index = content[term_index..-1].index("\\end") + term_index
95
+
96
+ term_index == -1 && break
97
+
98
+ end_index = content[term_index..].index("\\end") + term_index
98
99
  end
99
-
100
+
100
101
  content
101
102
  end
102
-
103
+
103
104
  def replace_term(term, content, replace_method)
104
105
  term_index = content.index(term)
105
- end_index = content[term_index..-1].index("\\end") + term_index
106
-
107
- while term_index > 0
106
+ end_index = content[term_index..].index("\\end") + term_index
107
+
108
+ while term_index.positive?
108
109
  term_content = content[term_index..(end_index + 3)]
109
- content = content[0..(term_index - 1)] + replace_method.call(term_content) + content[(end_index + 4)..-1]
110
+ content_before = content[0..(term_index - 1)]
111
+ content_after = content[(end_index + 4)..]
112
+ content = content_before + replace_method.call(term_content) + content_after
110
113
  term_index = content.index(term)
111
-
112
- if term_index.nil?
113
- break
114
- end
115
-
116
- end_index = content[term_index..-1].index("\\end") + term_index
117
-
114
+
115
+ term_index.nil? && break
116
+ end_index = content[term_index..].index("\\end") + term_index
117
+
118
118
  end
119
-
119
+
120
120
  content
121
121
  end
122
-
122
+
123
123
  def replace_axioms(content)
124
124
  @axiom_counter = 0
125
125
  replace_term("\\axiom", content, method(:replace_axiom))
126
126
  end
127
-
127
+
128
128
  def replace_definitions(content)
129
129
  @definition_counter = 0
130
130
  replace_term("\\definition", content, method(:replace_definition))
131
131
  end
132
-
132
+
133
133
  def replace_proofs(content)
134
134
  replace_term("\\proof", content, method(:replace_proof))
135
135
  end
136
-
136
+
137
137
  def convert(content)
138
138
  content = replace_theorems(content)
139
139
  content = replace_axioms(content)
140
140
  content = replace_definitions(content)
141
141
  content = replace_proofs(content)
142
-
143
-
144
- Jekyll::Converters::Markdown::KramdownParser.new(Jekyll.configuration()).convert(content)
142
+
143
+ Jekyll::Converters::Markdown::KramdownParser.new(Jekyll.configuration).convert(content)
145
144
  end
146
145
  end
147
146
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Euclid
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
data/lib/jekyll-euclid.rb CHANGED
@@ -1 +1,11 @@
1
- require "jekyll-euclid/version"
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+
5
+ require File.expand_path("jekyll/converters/euclid", File.dirname(__FILE__))
6
+
7
+ module Jekyll
8
+ # Euclid converter for Jekyll
9
+ module EuclidConverter
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-euclid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Nakayama
@@ -10,8 +10,8 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2024-10-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: This is a very simple attempt trying to mimic some of the behaviour found
14
- in LaTex theoremsi system.
13
+ description: This is a simple attempt trying to copy some of the behaviour found in
14
+ LaTex theoremsi system.
15
15
  email:
16
16
  - gui@tonkatsuengineering.com
17
17
  executables: []