mmmd 0.1.1 → 0.1.2

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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mmmd/blankshell.rb +63 -27
  3. data/test.md +1 -15
  4. data/test2.md +12 -0
  5. data/test3.md +1 -0
  6. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f64700645c2b97717469cd6da2ecd780138d0722f43f1503375e367f9574b718
4
- data.tar.gz: 153b9712bdb5ed0fe66681f64105152360bd50abf9aa907e97e5ef2f33ca3f2b
3
+ metadata.gz: 1a8790d6e9e6e5a9e3164e1f6f3ecf019cc73876d231676c562eb33925cea1a1
4
+ data.tar.gz: 738942fca7cea39dbd6fd4fcb15b46d643646e5c5fbb90593f7bf330f967c8ae
5
5
  SHA512:
6
- metadata.gz: dfe1a17ba166b8eb2076ef3097552d40fba6f1ea040b85d741ab650fe0794320ec20528b9887ac83c9b7620d5b6844805d0b12c0c7a8c547fd2cad889af1b046
7
- data.tar.gz: cd476ec80f1022b99115b3e6a0213ceca078d736fe3c3dce47aa3acd7404f15766d41e1324d2d90f84781b82a7f3a959df2c479584a02d28a3bf73b9f5ea5c81
6
+ metadata.gz: cc7e8c75e20ced1af9c502ebfc5453489c427a61f2c8b7e9e0fa26d50dcaf56df3f522c5e560fca0b27f4d06603ca8e6bb9a720f9dc00929c9c847f408301709
7
+ data.tar.gz: 03e2bcfff6462f28dc3439afdf02667a3944b6053e2b42da86fa2e1bfd4fffb8faa1bbfe2bcd4a0eaef006e6f22c9120a6cab365d475e294ccc3780e16dbba41
@@ -367,7 +367,7 @@ module PointBlank
367
367
 
368
368
  # (see ::PointBlank::Parsing::NullParser#consume)
369
369
  def consume(line, parent = nil, lazy: false)
370
- @lazy_triggered = lazy || @lazy_triggered
370
+ @lazy_triggered = lazy || @lazy_triggered unless line.strip.empty?
371
371
  return [nil, nil] if line.match?(/\A {0,3}\Z/)
372
372
  return [nil, nil] if @closed
373
373
  return [nil, nil] if check_candidates(line, parent)
@@ -957,9 +957,9 @@ module PointBlank
957
957
  parts = tokens
958
958
  @valid_parsers.each do |parser|
959
959
  newparts = []
960
- parts.each do |x|
960
+ parts.each_with_index do |x, i|
961
961
  if x.is_a? String
962
- newparts.append(*parser.tokenize(x))
962
+ newparts.append(*parser.tokenize(x, newparts.last, parts[i + 1]))
963
963
  else
964
964
  newparts.append(x)
965
965
  end
@@ -1013,8 +1013,10 @@ module PointBlank
1013
1013
 
1014
1014
  # Tokenize a string
1015
1015
  # @param string [String]
1016
+ # @param before [String, ::PointBlank::DOM::DOMObject]
1017
+ # @param after [String, ::PointBlank::DOM::DOMObject]
1016
1018
  # @return [Array<Array(String, Class, Symbol), String>]
1017
- def self.tokenize(string)
1019
+ def self.tokenize(string, _before, _after)
1018
1020
  [string]
1019
1021
  end
1020
1022
 
@@ -1142,18 +1144,11 @@ module PointBlank
1142
1144
  # Code inline parser
1143
1145
  class CodeInline < NullInline
1144
1146
  # (see ::PointBlank::Parsing::NullInline#tokenize)
1145
- def self.tokenize(string)
1146
- open = {}
1147
+ def self.tokenize(string, *_lookaround)
1147
1148
  iterate_tokens(string, "`") do |_before, current_text, matched|
1148
1149
  if matched
1149
1150
  match = current_text.match(/^`+/)[0]
1150
- if open[match]
1151
- open[match] = nil
1152
- [match, self, :close]
1153
- else
1154
- open[match] = true
1155
- [match, self, :open]
1156
- end
1151
+ [match, self, :open]
1157
1152
  else
1158
1153
  current_text[0]
1159
1154
  end
@@ -1170,9 +1165,9 @@ module PointBlank
1170
1165
  text = (part.is_a?(Array) ? part.first : part)
1171
1166
  buffer += text
1172
1167
  next unless part.is_a? Array
1168
+ next if idx.zero?
1173
1169
 
1174
- break (cutoff = idx) if part.first == opening &&
1175
- part.last == :close
1170
+ break (cutoff = idx) if part.first == opening
1176
1171
  end
1177
1172
  buffer = construct_literal(buffer[opening.length..(-1 - opening.length)])
1178
1173
  [cutoff.positive? ? build([buffer]) : opening, parts[(cutoff + 1)..]]
@@ -1182,7 +1177,7 @@ module PointBlank
1182
1177
  # Autolink inline parser
1183
1178
  class AutolinkInline < NullInline
1184
1179
  # (see ::PointBlank::Parsing::NullInline#tokenize)
1185
- def self.tokenize(string)
1180
+ def self.tokenize(string, *_lookaround)
1186
1181
  iterate_tokens(string, /[<>]/) do |_before, current_text, matched|
1187
1182
  if matched
1188
1183
  if current_text.start_with?("<")
@@ -1238,11 +1233,10 @@ module PointBlank
1238
1233
  linkinfo = capture[-1][2]
1239
1234
  obj = build(capture[1..-2])
1240
1235
  if linkinfo[:label]
1241
- if (props = doc.root.properties[:linkdefs][linkinfo[:label]])
1242
- linkinfo = props
1243
- else
1236
+ unless (props = doc.root.properties[:linkdefs][linkinfo[:label]])
1244
1237
  return nil
1245
1238
  end
1239
+ linkinfo = props
1246
1240
  end
1247
1241
  obj.properties = linkinfo
1248
1242
  obj
@@ -1277,7 +1271,7 @@ module PointBlank
1277
1271
  end
1278
1272
 
1279
1273
  # (see ::PointBlank::Parsing::NullInline#tokenize)
1280
- def self.tokenize(string)
1274
+ def self.tokenize(string, *_lookaround)
1281
1275
  iterate_tokens(string, /(?:!\[|\]\()/) do |_before, text, matched|
1282
1276
  next text[0] unless matched
1283
1277
  next ["![", self, :open] if text.start_with? "!["
@@ -1296,7 +1290,7 @@ module PointBlank
1296
1290
  end
1297
1291
 
1298
1292
  # (see ::PointBlank::Parsing::NullInline#tokenize)
1299
- def self.tokenize(string)
1293
+ def self.tokenize(string, *_lookaround)
1300
1294
  iterate_tokens(string, /(?:\[|\][(\[])/) do |_before, text, matched|
1301
1295
  next text[0] unless matched
1302
1296
  next ["[", self, :open] if text.start_with? "["
@@ -1308,20 +1302,61 @@ module PointBlank
1308
1302
  end
1309
1303
  end
1310
1304
 
1305
+ # TODO: this seems way too complicated for something that's supposed
1306
+ # to be a goddamn emphasis markup parser. i'd blame it on commonmark's
1307
+ # convoluted specs.
1308
+ # (P.S: it could be possible to make this easier for implementers by
1309
+ # making a claims system with pointers that do not modify the string
1310
+ # while it's being parsed. however that would just move complexity from
1311
+ # the parser into the scanner instead. and it does not resolve the
1312
+ # problem of overlapping claims as efficiently as simply splitting text
1313
+ # into tokens and remaining string bits.)
1314
+
1311
1315
  # Emphasis and strong emphasis inline parser
1312
1316
  class EmphInline < NullInline
1313
1317
  INFIX_TOKENS = /^[^\p{S}\p{P}\p{Zs}_]_++[^\p{S}\p{P}\p{Zs}_]$/
1314
1318
  # (see ::PointBlank::Parsing::NullInline#tokenize)
1315
- def self.tokenize(string)
1319
+ def self.tokenize(string, before, after)
1320
+ bfrb = extract_left(before)
1321
+ afra = extract_right(after)
1316
1322
  iterate_tokens(string, /(?:_++|\*++)/) do |bfr, text, matched|
1317
1323
  token, afr = text.match(/^(_++|\*++)(.?)/)[1..2]
1318
- left = left_token?(bfr[-1] || "", token, afr)
1319
- right = right_token?(bfr[-1] || "", token, afr)
1324
+ bfr = bfr[-1] || bfrb || ""
1325
+ afr = afr.empty? ? afra || "" : afr
1326
+ left = left_token?(bfr, token, afr)
1327
+ right = right_token?(bfr, token, afr)
1320
1328
  break_into_elements(token, [bfr[-1] || "", token, afr].join(''),
1321
1329
  left, right, matched)
1322
1330
  end
1323
1331
  end
1324
1332
 
1333
+ # Extract left-flanking token from before the tokenized string
1334
+ # @param bfr [String, ::PointBlank::DOM::DOMObject, Array(String, Class, Symbol)]
1335
+ # @return [String]
1336
+ def self.extract_left(bfr)
1337
+ case bfr
1338
+ when String
1339
+ bfr[-1]
1340
+ when ::PointBlank::DOM::DOMObject
1341
+ "."
1342
+ when Array
1343
+ bfr.first[-1]
1344
+ end
1345
+ end
1346
+
1347
+ # Extract right-flanking token from after the tokenized string
1348
+ # @param afr [String, ::PointBlank::DOM::DOMObject, Array(String, Class, Symbol)]
1349
+ # @return [String]
1350
+ def self.extract_right(afr)
1351
+ case afr
1352
+ when String
1353
+ afr[0]
1354
+ when ::PointBlank::DOM::DOMObject
1355
+ "."
1356
+ when Array
1357
+ afr.first[0]
1358
+ end
1359
+ end
1325
1360
  # Is this token, given these surrounding characters, left-flanking?
1326
1361
  # @param bfr [String]
1327
1362
  # @param token [String]
@@ -1386,8 +1421,9 @@ module PointBlank
1386
1421
  ((blk.first.length % 3).zero? &&
1387
1422
  (closer.first.length % 3).zero?))
1388
1423
  (open ? capture : before).prepend(blk)
1389
- next unless blk.is_a?(Array)
1390
- return backlog unless blk[1].check_contents(capture)
1424
+ next unless blk.is_a?(Array) && !open
1425
+
1426
+ return backlog unless closer[1].check_contents(capture)
1391
1427
  end
1392
1428
  return backlog if open
1393
1429
 
@@ -1431,7 +1467,7 @@ module PointBlank
1431
1467
  # Hard break
1432
1468
  class HardBreakInline < NullInline
1433
1469
  # (see ::PointBlank::Parsing::NullInline#tokenize)
1434
- def self.tokenize(string)
1470
+ def self.tokenize(string, *_lookaround)
1435
1471
  iterate_tokens(string, /(?: \n|\\\n)/) do |_before, token, matched|
1436
1472
  next ["\n", self, :close] if token.start_with?(" \n")
1437
1473
  next ["\n", self, :close] if matched
data/test.md CHANGED
@@ -1,15 +1 @@
1
- Jabronicle Mitch's wild ride
2
- ============================
3
-
4
- crusty cocks
5
-
6
- -------------
7
-
8
- - DIIIIICKS
9
- - - let
10
- - me
11
- - smell
12
- - your
13
- - dick
14
- - [anime feet](https://google.com)
15
- - [goog](https://goog.com 'goog')
1
+ tokens blahblah **[test](/pee)** more tokens
data/test2.md ADDED
@@ -0,0 +1,12 @@
1
+ > **Quote block**
2
+ >
3
+ > a**.not even emphasis.**b
4
+ >
5
+ > a**[neither is this emphasis](/uri 'but should it be?')**x
6
+ >
7
+ > **[emphasized image link ![image](/uri)](/link)**
8
+ >
9
+ > titlet
10
+ > ======
11
+ >
12
+ > amongus
data/test3.md ADDED
@@ -0,0 +1 @@
1
+ **test<http://autolink`>[stuff`[dat](#lonk)[`...](#stuff)**
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yessiest
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir:
10
10
  - bin
11
11
  cert_chain: []
12
- date: 2025-03-09 00:00:00.000000000 Z
12
+ date: 2012-01-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: |
15
15
  MMMD (short for Mark My Manuscript Down) is a Markdown processor
@@ -24,6 +24,8 @@ extra_rdoc_files:
24
24
  - architecture.md
25
25
  - security.md
26
26
  - test.md
27
+ - test2.md
28
+ - test3.md
27
29
  files:
28
30
  - README.md
29
31
  - architecture.md
@@ -37,6 +39,8 @@ files:
37
39
  - lib/mmmd/util.rb
38
40
  - security.md
39
41
  - test.md
42
+ - test2.md
43
+ - test3.md
40
44
  homepage: https://adastra7.net/git/Yessiest/rubymark
41
45
  licenses:
42
46
  - AGPL-3.0-or-later