Created
August 12, 2016 17:00
-
-
Save tzmartin/070d805d308ea4dfdaafafcbd2c007ec to your computer and use it in GitHub Desktop.
determine line numbers and starting position from a single markdown string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
src = '# Magic Deck\n\n## A markdown editor for creating magical slide shows\n\n---\n\n# How to Use\n\nJust use `---` for each slide and markdown syntax to make it look pretty.\n\nWhen you\'re ready, just use `⌘+R` to render.\n\n---\n\n# Your Turn\n\n'; | |
var index = src.match(new RegExp('---\n\n', "gi")).length; | |
console.log('Found: ' + index); | |
var pos = src.indexOf('---\n\n', 75); | |
console.log('Pos: ' + pos); | |
var tempString = src.substring(0, pos); | |
var lineNumber = tempString.split('\n').length; | |
console.log(lineNumber); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment