Open GaurangTandon opened 7 years ago
Additionally, is it possible to not require the date/time fields be space delimited? for example, to have [[%d(YYYYMMD)]] return 20180724 instead of YYYYMMDD as it currently does.
@TheITJuggler thanks for your feedback! I've been thinking about this for a day and here are my thoughts:
The way this works currently: find a single [[%d(text)]]
block. Then loop through all the macros (listed on the Help page), in the order from top to bottom, and then replace each occurrence of that macro (inside of the text
) with its value, performing concerned date/time arithmetic.
The crucial part here is that the occurrence of a macro (inside of the text
) are searched by surrounding that macro with word boundaries (\b
). This makes it impossible for macro to match with YYYYMMDD
, as you've already observed.
Scrapping the word boundary would lead to the problematic replacement of the a
in date
. The only way to then fix this problem is to: a) change a
to something else and b) ensure that all future macro additions are such that the predecessor is not a substring of any of its successors.
However, the problem's still not fixed because now the D
- for example - could match the output of
MMMM
(Dec
). Then, we would require to store replacements in a new output string. So, the final solution is to first tokenize the input string into separate macros. Say, for example, the input is [[%d(YYY @ MM)]]
. The tokenizer would split this into an array of macros and non-macros ["YYY", " @ ", "MM"]
(by looping through macros in priority order). Now the replacements can be performed without any trouble.
Given the complexity of this rewrite, I'll likely want to defer it for a future release. Sorry @TheITJuggler ! And thanks for your feedback!
Concerned code:
// get array of string macros
var list = Snip.MACROS.reduce((prev, curr) => prev.concat(curr[0]), []);
// remove word boundaries
list = list.map(e => e.replace(/(^\\b)|(\\b$)/, ""));
// log substring pairs
for(var i = 0, len = list.length; i < len; i++){
for(var j = i + 1; j < len; j++){
if(list[j].indexOf(list[i]) > -1) console.log(list[i], list[j + 1]);
}
}
Thanks for taking a look at it. I used to use another Chrome plugin to do my shortcode work, but that now doesn't work with the new TinyMCE-ish editor that has been installed; Prokey filled that gap quite nicely. Of all the shortcodes I have, the only one I had was the YYYYMMD one. And I can appreciate that its not a small change as you have to modify your parsing to make it work.
Thanks for considering it..
Steve Ollis
"There are 10 types of people in this world - Those that can count in binary, and those that can't."
On Wed, Jul 25, 2018 at 7:59 PM Gaurang Tandon notifications@github.com wrote:
@TheITJuggler https://github.com/TheITJuggler thanks for your feedback! I've been thinking about this for a day and here are my thoughts:
The way this works currently: find a single [[%d(text)]] block. operate on this block, then loop through all the macros (listed on the Help page), in the order from top to bottom, and then replace each occurrence of that macro (inside of the text) with its value, performing concerned date/time arithmetic.
The crucial part here is that the occurrence of a macro (inside of the text) are searched by surrounding that macro with word boundaries (\b). This makes it impossible for macro to match with YYYYMMDD, as you've already observed.
Scrapping the word boundary would lead to the problematic replacement of the a in date. The only way to then fix this problem is to: a) change a to something else and b) ensure that all future macro additions are such that the predecessor is not a substring of any of its successors.
However, the problem's still not fixed because now the D - for example - could match the output of MMMM (Dec). Then, we would require to store replacements in a new output string. So, the final solution is to first tokenize the input string into separate macros. Say, for example, the input is [[%d(YYY @ MM)]]. The tokenizer would split this into an array of macros and non-macros ["YYY", " @ ", "MM"] (by looping through macros in priority order). Now the replacements can be performed without any trouble.
Given the complexity of this rewrite, I'll likely want to defer it for a future release. Sorry @TheITJuggler https://github.com/TheITJuggler ! And thanks for your feedback!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GaurangTandon/ProKeys/issues/179#issuecomment-407701939, or mute the thread https://github.com/notifications/unsubscribe-auth/ABXy_r1IJjSkOiQcxA98zAgxowU74xD2ks5uKEGRgaJpZM4OLTPc .
We need to add the following macros (arrived this list after having checked textexpander and phraseexpress):
1s
(prefix of1
) wheres
stands for hour (12h, 24h) minutes, seconds, month, date to support single digit hours/minutes/etc. as well i.e. to expand to3
instead of03
, but expands to12
as usual.Z
: abbrev timezone (IST
) (use this code reference)ZZ
: complete timezone (India Standard Time
)z
: GMT offset (Date.prototype.getTimezoneOffset()
)J
= numerical day of year (code)