legal_markdown 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,7 +20,7 @@ After the gem has finished its installation on your system then you can simply t
20
20
 
21
21
  [YAML](http://www.yaml.org/spec/1.2/spec.html) is about the easiest thing to create. At the top of your file (it MUST be at the top of the file) you simply put in three or more hyphens like so: `---` on a single line. Then on the next line you simply put in the `field` followed by a `:` (colon) followed by the `value`. For each line you put the `[field]: [value]` until you have filled everything in that you need. After you have put in all your YAML front-matter then you simply put in a single line with three more hyphens `---` to signal to the gem that it is the end of the fields. So this would look like this:
22
22
 
23
- ```yaml
23
+ ```
24
24
  ---
25
25
  title: My Perfect Contract
26
26
  author: Watershed Legal Services
@@ -36,7 +36,7 @@ The gem will normally strip out the YAML front-matter as most markdown renderers
36
36
 
37
37
  To leave the YAML front-matter there simply pass the `value` of `true` to the `field` called `leave_yaml_front_matter`; this is how it would look in the above example.
38
38
 
39
- ```yaml
39
+ ```
40
40
  ---
41
41
  title: My Perfect Contract
42
42
  author: Watershed Legal Services
@@ -57,20 +57,20 @@ Mixins are straight-forward they are simple markers that can be used throughout
57
57
 
58
58
  Mixins are structured in the form of **double curly** brackets (this was taken from IFTTT). So, for a `{{court}}` mixin, the YAML front-matter would look like this:
59
59
 
60
- ```yaml
60
+ ```
61
61
  {{court}}: Regional Court of Hargeisa
62
62
  ```
63
63
 
64
64
  Mixins can also be used to set up clauses in the alternative in your templates which can be turned on or off within a specific document simply by updating the YAML mixin to false. Example of a `{{provision12a}}{{provision12b}}` alternative structuring for a contract template. Within the template the YAML front-matter would be structured something like this:
65
65
 
66
- ```yaml
66
+ ```
67
67
  {{provision12a}}: "For the purposes of this Agreement"
68
68
  {{provision12b}}: "This Agreement shall"
69
69
  ```
70
70
 
71
71
  Then to chose one of the two provisions you would would simply change the line to "false" but without the quotes. Example:
72
72
 
73
- ```yaml
73
+ ```
74
74
  {{provision12a}}: false
75
75
  ```
76
76
 
@@ -82,19 +82,31 @@ In order to address this problem, I have built functionality into legal_markdown
82
82
 
83
83
  Then you can describe the functionality that you require in the YAML front-matter. In the YAML front-matter you will simply add the following fields: `level-1` and then the `: ` followed by what the format you would like it to be in. Currently there are a few possible options at this time (for those using pandoc at least):
84
84
 
85
- 1. `level-1: 1.` will format that level of the list as 1. 2. 3. etc.; This is the default functionality;
86
- 2. `level-1: (1)` will provide for the same numbering only within parenteticals rather than followed by a period;
87
- 3. `level-1: A.` will format with capital letters followed by a period (e.g, A., B., C., etc.);
88
- 4. `level-1: (A)` will format the same as the above only with the capital letters in a parentetical;
89
- 5. `level-1: a.` will format with lowercase letters followed by a period;
90
- 6. `level-1: (a)` will format with lowercase letters within a parentethical;
91
- 7. `level-1: I.` will format with capital Roman numerals followed by a period;
92
- 8. `level-1: (I)` will format with capital Roman numerals within a parententical;
93
- 9. `level-1: i.` will format with lowercase Roman numerals followed by a period;
94
- 10. `level-1: (i)` will format with lowercase Roman numerals within a parententical..
85
+ 1. `level-1: 1.` will format that level of the list as 1. 2. 3. etc.; This is the default functionality;
86
+ 2. `level-1: (1)` will provide for the same numbering only within parenteticals rather than followed by a period;
87
+ 3. `level-1: A.` will format with capital letters followed by a period (e.g, A., B., C., etc.);
88
+ 4. `level-1: (A)` will format the same as the above only with the capital letters in a parentetical;
89
+ 5. `level-1: a.` will format with lowercase letters followed by a period;
90
+ 6. `level-1: (a)` will format with lowercase letters within a parentethical;
91
+ 7. `level-1: I.` will format with capital Roman numerals followed by a period;
92
+ 8. `level-1: (I)` will format with capital Roman numerals within a parententical;
93
+ 9. `level-1: i.` will format with lowercase Roman numerals followed by a period;
94
+ 10. `level-1: (i)` will format with lowercase Roman numerals within a parententical..
95
95
 
96
96
  Obviously you will replace `level-1` with `level-2`, etc. Although this functionality was built into the gem, it is generally not the best practice. A better practice is to let the gem make the replacements and reformat the markdown and then use your rendering system and its default reference documents to set the styles you need.
97
97
 
98
+ ## No Reset Function
99
+
100
+ Sometimes in legal documents (particularly in laws) you want to build multiple structured header levels, but you do not want to reset all of the headers when going up the tree. For example, in some laws you will have Chapters, Parts, Sections, ... and you will want to track Chapters, Parts and Sections but when you go up to Parts you will not want to reset the Sections to one.
101
+
102
+ This functionality is built in with a `no-reset` function. You simply add a `no-reset` field to your YAML header and note the headers that you do not want to reset by their l., ll. notation. Separate those levels you do not want reset with commas. Example YAML line:
103
+
104
+ ~~~
105
+ no-reset: l., ll., lll.
106
+ ~~~
107
+
108
+ This will not reset level-1, level-2, or level-3 when it is parsing the document and those levels will be numbered sequentially through the entire block rather than reseting when going to a higher block, levels not in this reset, e.g., llll. and lllll. will be reset when going up a level in the tree. Obviously the level 1 headers will never reset.
109
+
98
110
  ## Example
99
111
 
100
112
  If you use a system like Pandoc you can establish a system wherein the styles that you establish in the reference.docx or reference.odt or the latex style references can make up for the lack of granular fuctionality. When you build your reference.odt for example and you want to have a contract look like this:
@@ -131,7 +143,7 @@ You can easily to that by doing the following steps.
131
143
 
132
144
  ### Step 2: (Optional) Fill out the YAML Front-Matter
133
145
 
134
- ```yaml
146
+ ```
135
147
  ---
136
148
  title: Wonderful Contract
137
149
  author: Your Name
@@ -160,7 +172,7 @@ Then you would save the reference.odt as a new name perhaps contract-reference.o
160
172
 
161
173
  Now that you've been warned, here's how you use precursors. Within the text of the document nothing changes. In the YAML front matter you will leave it as it was before. All you need to do is add any word or other marker before the trigger. What `legal_markdown` will do is to look at the last two characters if the marker ends in a period or three if it ends in a paren, and then everything else it will place into a precursor. If you want to reference the preceding level (like 1.1.1 in the example above) then simply put in {pre}. I'll try to make this less fragile down the road, but for now it is what it is. So, your YAML front matter will look like this:
162
174
 
163
- ```yaml
175
+ ```
164
176
  ---
165
177
  title: Wonderful Contract
166
178
  author: Your Name
@@ -181,21 +193,27 @@ I do not use latex to create pdfs nor do I use Word, but the functionality will
181
193
 
182
194
  ## A Few Gotchas
183
195
 
184
- You cannot begin the block of structured headers with a second level header. The gem searches the markdown to find a line that begins with `l.` where there is a blank line above it. This is made to be fairly precise so as to ensure that the gem does not strip out some other functionality that you want to build.
196
+ * When you are using structured headers of legal_markdown you should make the lists tight. Do not add blank lines in between the list levels or the gem will think you are creating a new list. If you are trying to create a new list then by all means go ahead as the blank lines will break the parsing. On the roadmap is functionality for multiple blocks, but at this point in the Gem's development it will only run one block through the modification methods.
197
+ * If you use the reference.odt or reference.docx to override the default formating of the list then it is not optimal add level-1 or level-2 leading text or utilize the different marker functionality (e.g., (i) or (a) and the like) to the YAML front-matter. The optimal way is to use the defaults that pandoc has or whatever renderer you use along with legal_markdown to set the spacing and then use the reference styles to build the functionality that you would like from the word processor side. The leading text and different marker systems are predominately built for html output.
198
+ * Legal_markdown is optimized primarily for contracts, legislation, and regulations. It is not optimized for cases. For memoranda and filings I use the mixin portion but not the header portion which is enough to meet my needs - in particular, when matched with Sublime Text snippets. If you area looking for a more complete solution for cases and filings I would recommend the [Precedent Gem](https://github.com/BlackacreLabs/precedent) built by [Kyle Mitchell](https://github.com/kemitchell) for [Blackacre Labs](https://github.com/BlackacreLabs)
185
199
 
186
- When you are using structured headers of legal_markdown you should make the lists tight. Do not add blank lines in between the list levels or the gem will think you are creating a new list. If you are trying to create a new list then by all means go ahead as the blank lines will break the parsing.
200
+ # TODO
187
201
 
188
- Also, if you use the reference.odt or reference.docx to override the default formating of the list then you do not need to add any level-1 or level-2 fields to the YAML front-matter. The best way to do it is to simply use the defaults that pandoc or your renderer will use and then use the reference styles to build the functionality that you would like.
202
+ [ ] Definitions. For now these can be used as mixins but that functionality needs to improve.
189
203
 
190
- # TODO
204
+ [ ] Make a no-reset option for certain levels that should not reset when moving up the tree.
205
+
206
+ [ ] Parsing. At this point legal_markdown cannot take a markdown document and parse it to build structured headers. Legal_markdown only works with a renderer to *create* documents but not to *import* documents. I want to build this functionality out at a later date. Legal_markdown is not meant as an importer for files types, there are other tools for that but I would like it to be able to parse text that is already in markdown.
207
+
208
+ [ ] Markdown post-processing. This will cure some of the issues (class establishment and proper list nesting of structure documents) that are currently lost when using precurors.
191
209
 
192
- [ ] - Definitions. For now these can be used as mixins but that functionality needs to improve.
210
+ [ ] Different input and output files.
193
211
 
194
- [ ] - Parsing. At this point legal_markdown cannot take a markdown document and parse it to build structured headers. Legal_markdown only works with a renderer to *create* documents but not to *import* documents. I want to build this functionality out at a later date. Legal_markdown is not meant as an importer for files types, there are other tools for that but I would like it to be able to parse text that is already in markdown.
212
+ [ ] Implement partials.
195
213
 
196
- [ ] - Markdown post-processing. This will cure some of the issues (class establishment and proper list nesting of structure documents) that are currently lost when using precurors.
214
+ [ ] Small capitals based on [Precedent's Syntax](https://github.com/BlackacreLabs/precedent/blob/master/SYNTAX.md).
197
215
 
198
- [ ] - Different input and output files
216
+ [ ] Handle against multiple blocks in a document as this currently will not work.
199
217
 
200
218
  # Contributing
201
219
 
data/Rakefile CHANGED
@@ -1,34 +1,2 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
- # begin
4
- # require "mg"
5
- # MG.new("legal_markdown.gemspec")
6
- # rescue LoadError
7
- # nil
8
- # end
9
-
10
- # desc "Build standalone script"
11
- # task :build => [ :standalone ]
12
-
13
- # desc "Build standalone script"
14
- # task :standalone => :load_legal_markdown do
15
- # require 'legal_markdown/standalone'
16
- # LegalMarkdown::Standalone.save('legalmd')
17
- # end
18
-
19
- # Rake::TaskManager.class_eval do
20
- # def remove_task(task_name)
21
- # @tasks.delete(task_name.to_s)
22
- # end
23
- # end
24
-
25
- # # Remove mg's install task
26
- # Rake.application.remove_task(:install)
27
-
28
- # desc "Install standalone script"
29
- # task :install => :standalone do
30
- # prefix = ENV['PREFIX'] || ENV['prefix'] || '/usr/local'
31
-
32
- # FileUtils.mkdir_p "#{prefix}/bin"
33
- # FileUtils.cp "legalmd", "#{prefix}/bin"
34
- # end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
3
  # == USAGE
4
- # legalmd file.md
4
+ # md2legal file.md
5
5
 
6
6
  require 'legal_markdown'
7
- LegalMarkdown.markdown_preprocess(ARGV)
7
+ LegalMarkdown.markdown_to_legal(ARGV)
@@ -1,3 +1,3 @@
1
1
  module LegalMarkdown
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -7,7 +7,7 @@ require "legal_markdown/version"
7
7
  module LegalMarkdown
8
8
  extend self
9
9
 
10
- def markdown_preprocess(*args)
10
+ def markdown_to_legal(*args)
11
11
  # Get the Content & Yaml Data
12
12
  data = load(*args)
13
13
  parsed_content = parse_file(data[0])
@@ -157,9 +157,9 @@ module LegalMarkdown
157
157
  elsif value =~ /\([a-z]\)\z/ # type8 : {{ (a) }}
158
158
  return[:type8, value[0..-4]]
159
159
  elsif value =~ /\(\d\)\z/ # type9 : {{ (1) }}
160
- return[:type9, value[0..-3]]
160
+ return[:type9, value[0..-4]]
161
161
  else value =~ /\d\.\z/ # type0 : {{ 1. }} ... also default
162
- return[:type0, value[0..-4]]
162
+ return[:type0, value[0..-3]]
163
163
  end
164
164
  end
165
165
 
@@ -172,6 +172,10 @@ module LegalMarkdown
172
172
  # substitutions hash example {"ll."=>[:type8,"Article"],}
173
173
  substitutions[search]= set_the_subs_arrays(value.to_s)
174
174
  end
175
+ if header =~ /no-reset/
176
+ no_subs_array = value.split(", ")
177
+ no_subs_array.each{|e| substitutions[e][6] = :no_reset }
178
+ end
175
179
  end
176
180
 
177
181
  return substitutions
@@ -197,25 +201,35 @@ module LegalMarkdown
197
201
  def get_the_subs_arrays( value )
198
202
  # returns a new array for the replacements
199
203
  if value[0] == :type1 # :type1 : {{ I. }}
200
- return[:type1, value[1], "", "I", "."]
204
+ value[2..4] = [ "", "I", "." ]
205
+ return value
201
206
  elsif value[0] == :type2 # :type2 : {{ (I) }}
202
- return[:type2, value[1], "(", "I", ")"]
207
+ value[2..4] = [ "(", "I", ")"]
208
+ return value
203
209
  elsif value[0] == :type3 # :type3 : {{ i. }}
204
- return[:type3, value[1], "", "i", "."]
210
+ value[2..4] = [ "", "i", "."]
211
+ return value
205
212
  elsif value[0] == :type4 # :type4 : {{ (i) }}
206
- return[:type4, value[1], "(", "i", ")"]
213
+ value[2..4] = [ "(", "i", ")"]
214
+ return value
207
215
  elsif value[0] == :type5 # :type5 : {{ A. }}
208
- return[:type5, value[1], "", "A", "."]
216
+ value[2..4] = [ "", "A", "."]
217
+ return value
209
218
  elsif value[0] == :type6 # :type6 : {{ (A) }}
210
- return[:type6, value[1], "(", "A", ")"]
219
+ value[2..4] = [ "(", "A", ")"]
220
+ return value
211
221
  elsif value[0] == :type7 # :type7 : {{ a. }}
212
- return[:type7, value[1], "", "a", "."]
222
+ value[2..4] = [ "", "a", "."]
223
+ return value
213
224
  elsif value[0] == :type8 # :type8 : {{ (a) }}
214
- return[:type8, value[1], "(", "a", ")"]
225
+ value[2..4] = [ "(", "a", ")"]
226
+ return value
215
227
  elsif value[0] == :type9 # :type9 : {{ (1) }}
216
- return[:type9, value[1], "(", "1", ")"]
228
+ value[2..4] = [ "(", "1", ")"]
229
+ return value
217
230
  else value[0] == :type0 # :type0 : {{ 1. }} ... also default
218
- return[:type0, value[1], "", 1, "."]
231
+ value[2..4] = [ "", 1, "."]
232
+ return value
219
233
  end
220
234
  end
221
235
 
@@ -258,11 +272,13 @@ module LegalMarkdown
258
272
  leaders_to_reset = []
259
273
  hash_of_subs.each_key{ |k| leaders_to_reset << k if k > selector }
260
274
  leaders_to_reset.each do | leader |
261
- unless hash_of_subs[leader][5] == :pre
262
- hash_of_subs[leader]= get_the_subs_arrays(hash_of_subs[leader])
263
- else
264
- hash_of_subs[leader]= get_the_subs_arrays(hash_of_subs[leader])
265
- hash_of_subs[leader]= pre_setup(hash_of_subs[leader])
275
+ unless hash_of_subs[leader][6] == :no_reset
276
+ unless hash_of_subs[leader][5] == :pre
277
+ hash_of_subs[leader]= get_the_subs_arrays(hash_of_subs[leader])
278
+ else
279
+ hash_of_subs[leader]= get_the_subs_arrays(hash_of_subs[leader])
280
+ hash_of_subs[leader]= pre_setup(hash_of_subs[leader])
281
+ end
266
282
  end
267
283
  end
268
284
  return hash_of_subs
@@ -285,7 +301,7 @@ module LegalMarkdown
285
301
  new_block = ""
286
302
  leader_before = ""
287
303
  leader_above = ""
288
- selector_before = ""
304
+ selector_before = ""
289
305
  old_block.each_line do | line |
290
306
  selector = $1.chop if line =~ /(^l+.\s)/
291
307
  sub_it = substitutions[selector]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legal_markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-21 00:00:00.000000000 Z
12
+ date: 2013-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: roman-numerals
@@ -36,7 +36,7 @@ description: ! " This gem will parse YAML Front Matter of Markdown Documents. T
36
36
  that. Why? Because Word is awful. \n"
37
37
  email: caseykuhlman@watershedlegal
38
38
  executables:
39
- - legalmd
39
+ - md2legal
40
40
  extensions: []
41
41
  extra_rdoc_files: []
42
42
  files:
@@ -45,7 +45,7 @@ files:
45
45
  - LICENSE
46
46
  - README.md
47
47
  - Rakefile
48
- - bin/legalmd
48
+ - bin/md2legal
49
49
  - legal_markdown.gemspec
50
50
  - lib/legal_markdown.rb
51
51
  - lib/legal_markdown/version.rb
@@ -63,7 +63,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
63
  version: '0'
64
64
  segments:
65
65
  - 0
66
- hash: 2506371109805164331
66
+ hash: 1157519025930477197
67
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  none: false
69
69
  requirements:
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  version: '0'
73
73
  segments:
74
74
  - 0
75
- hash: 2506371109805164331
75
+ hash: 1157519025930477197
76
76
  requirements: []
77
77
  rubyforge_project:
78
78
  rubygems_version: 1.8.25