Find and Replace via GREP in InDesign in a specific manner - adobe-indesign

I am currently trying to layout a novel in InDesign. In the original text the chapters are headlined with "## Chapter X" because it is written in Markdown.
So I try to automate the layouting using GREP and try to apply a specific paragraph style to the headlines.
I use the following syntax to accomplish that:
## \w+ \d
But what it does, of course, is that the whole phrase "## Chapter X" is set in this style. Is there any way to apply the paragraph style AND remove the "##"?
Thanks a lot!

In find field : (## )(\w+ \d)
In change field : $2;

Related

Finding head section of HTML in Emeditor

I'm trying to use EmEditor to do some find and replace on HTML using regex. I know that Regex is not generally suitable for HTML parsing but I believe it will work for my limited requirement. I can't get it to do some fairly simple finds. e.g. find the head section and remove it. I've tried several different syntaxes e.g. <head.*?>(.|\n)*?</head> also simpler ones where there are no attributes e.g. <head>.*?</head>. None work. What am I doing wrong?
Please try a non-zero value to the Additional Lines to Search for Regular Expressions text box in the Advanced dialog box (Click the Advanced button in the Find dialog box) if you need to search for multi-line strings.

Is there a way to add comments to localized strings in Interface Builder?

In code, the NSLocalizedString macro lets you give a descriptive comment along with your string, so your translators have the necessary context to write a translation. However, I don't see any way to give an equivalent comment along with the strings in my storyboard. Instead, the xliff file contains notes like this:
Class = "NSTextFieldCell"; title = "Created"; ObjectID = "1u4-pn-J7a";
Not very useful. Is there any way for me to provide my translators with better explanations of the purpose/placement of these strings?
There is a way to do this. In the Identity inspector, under Document, there is a section called Notes. Text added to this section will be included in the <note> section of an item in the xliff file.
Inside the section you can also add text= and then whatever you want to tell the translator.
Alternatively, if you end up working out of a text file, you can also add a note above or below the string inside forwarded slashes e.g.
"00_bkm_11"="Bookmark";
/Used to mean save a webpage in the app/
Hope these two help :-)

sed - add text to variable

i have html code like this
Something cool, Nice Text
some text
Apple's text
and i need add dots (beginning) and .html's (end) to links to get this:
Something cool, Nice Text
some text
Apple's text
I was playing with sed, but i have no idea, how to work with changed urls.
Something like
look for "/site/index.php/ and first occurrence of " and before that " put .html (or after variable between).
Thank you.
sed 's/<a \+href="\([^\"]*\)"/<a href=".\1.html"/g' my_file.html
This looks for anything that looks like <a href="xxx" and replaces the xxx with .xxx.html. It allows more than one space between a and href. To find xxx, it looks for any string between " that doesn't contains ". This assumes your original contains a preceding / as your example shows, and that the <a href="xxx" is all on the same line in the file (not broken between a and href for example). The g option will make sure it takes care of multiple hrefs on a single line.
Using awk
awk '{gsub(/href="/,"&.");gsub(/" title/,".html&")}1' file

How can I query XPath matching an attribute from one tag against another attribute from another tag?

I'm scripting a web app that has labels for input fields. EG:
<label for="surname">Family Name:</label>...<input id="surname" ...></input>
I'd like to be able to write an XPath expression that takes the text "Family Name:" to match the label, then takes the "for" attribute from the label and uses that to find the associated input tag by matching its "id" tag.
I can make this "work" as follows:
//label[contains(.,"Family Name:")]/following::input[1]
However, for this web app I think it would be more reliable to match for/id. (EG: How can I be sure that in all possible layouts the first input tag following the label is the one I want? And what happens if somewhere down the line this page is rendered using a right-to-left script?
My ultimate aim is to create a library function that we can use to write QA scripts in advance of web pages to test against, when all we have is a picture or document with an input field labelled "Family Name:" and no idea what id some programmer will ultimately assign to the field.
Maybe this is what you're looking for?
//input[#id = //label[contains(., "Family Name:")]/#for]
As for your ultimate goal, you may want to take a look at the XPath gem for Ruby. Some of what you're doing may already be implemented there. (Specifically, check out the library's HTML Helpers)

Selected text in ruby Tk Text widget?

I can't seem to find how to get the currently selected text from a Text widget in ruby. In perl there was a ->getSelected function, which does not seem to exist in the ruby implementation. Also, the selected text is supposed to be marked with a tag "sel", but whenever I try to use it with get("sel"), it says invalid text index. There must be a way to get the selected text though...
Also, another question, by default, the text widget in perl has a pop menu with all sorts of functionality like search, copy/paste. Was this just a perl specific add on?
Yes, the popup menu in perl is a perl-specific add-on.
As for getting the selected text, you are correct that the selected text has the "sel" tag, and you use that to get the selected text. To retrieve the selected text you should use the index sel.first and sel.last, for example:
get("sel.first", "sel.last")
A really good resource on Tk that covers usage in Tcl, Python, Ruby and Perl see tkdocs.com. The text widget is documented on that site in the tutorial on text.
Of course I finally figured this out right after posting. The index is "sel.first" and "sel.last". so I used get("sel.first", "sel.last")

Resources