Last active
April 11, 2020 16:23
-
-
Save line0/28bb9d817afcfaabdf9fe21af7d9d861 to your computer and use it in GitHub Desktop.
l0.ReplaceByCharacterText.moon
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
export script_name = "Replace Character By Text" | |
export script_description = "Takes GBC lines and replaces each character from a sequence of matching length in the effect field" | |
export script_version = "0.1.0" | |
export script_author = "line0" | |
export script_namespace = "l0.ReplaceByCharacterText" | |
DependencyControl = require "l0.DependencyControl" | |
depCtrl = DependencyControl{ | |
feed: "https://raw.githubusercontent.com/TypesettingTools/line0-Aegisub-Scripts/master/DependencyControl.json", | |
{ | |
{"a-mo.LineCollection", version: "1.3.0", url: "https://github.com/TypesettingTools/Aegisub-Motion", | |
feed: "https://raw.githubusercontent.com/TypesettingTools/Aegisub-Motion/DepCtrl/DependencyControl.json"}, | |
{"l0.ASSFoundation", version: "0.4.0", url: "https://github.com/TypesettingTools/ASSFoundation", | |
feed: "https://raw.githubusercontent.com/TypesettingTools/ASSFoundation/master/DependencyControl.json"}, | |
{"l0.Functional", version: "0.5.0", url: "https://github.com/TypesettingTools/Functional", | |
feed: "https://raw.githubusercontent.com/TypesettingTools/Functional/master/DependencyControl.json"}, | |
} | |
} | |
LineCollection, ASS, Functional = depCtrl\requireModules! | |
{:list, :math, :string, :table, :unicode, :util, :re } = Functional | |
logger = depCtrl\getLogger! | |
process = (sub, sel, res) -> | |
lines = LineCollection sub, sel | |
cb = (lines, line, i) -> | |
data = ASS\parse line | |
-- chars = unicode.toCharTable line.effect -- whitespaces get their own section | |
chars = [c for c in re.matches line.effect, "[^\\s]\\s*"] -- whitespaces appended to the section of the previous char | |
textSectionCb = (section, _, _, j) -> | |
section.value = chars[j] | |
data\callback textSectionCb, ASS.Section.Text | |
data\commit! | |
lines\runCallback cb, true | |
lines\replaceLines! | |
depCtrl\registerMacro process |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment