I have quite a lot of anchors to picture in doxygen, e.g.
\anchor pic_foo
\image html foo.gif "My Caption"
\anchor pic_bar
\image html bar.gif "My Caption"
Everytime when I use \ref to link one of those, I have to make up
some nice description so the raw name of the anchor doesn't appear in
output.
Is it possible to have something like numbered anchors in doxygen
where the link text will be the number of that anchor? Ideally
something like:
\anchor pic_foo
\image html foo.gif "My Caption"
\anchor pic_bar
\image html bar.gif "My Caption"
As Figure \ref pic_foo shows... Figure \ref pic_bar is...
should ideally translate to:
As Figure 1 shows... Figure 2 is...
where the number is the link. I would be happy with every kind of counting scheme (documentation global or page local).
I don't think that automatic number of figures, either within a page or across the whole documentation, is possible with doxygen (I would be happy to be corrected here). However, an easy solution to your question is the replace your anchor text with spelt out numbers, i.e. "one", "two", "three"... etc. Alternatively, if you have lots of figures you could use Roman numerals. Plain numbers don't seem to work as anchor links.
Your example will then become, with additional text in the figure captions,
\anchor one
\image html foo.gif "Figure one: My Caption"
\anchor two
\image html bar.gif "Figure two: My Caption"
As Figure \ref one shows... Figure \ref two is...
resulting in
Here Figure one shows... Figure two is...
with one and two hyperlinks to your figures.
You can then define a alias in your configuration file, say \fref, defined to be Figure \ref which will automatically preceed the hyperlinked numbers with the text "Figure".
Is this solution acceptable? The only other alternative I can think of involves post processing the doxygen output, but the above solution is by far the simplest.
Update
The following Python code will transform anchor references to an incrementing counter:
# Test documentation.
s = r"""
\anchor pic_foo
\image html foo.gif "My Caption"
\anchor pic_bar
\image html bar.gif "My Caption"
As Figure \ref pic_foo shows... Figure \ref pic_bar is...
"""
# Split string into a list of lines.
s = s.split('\n')
# Dictionaries for mapping anchor names to an incrementing counter.
d = {}
numbers = {1: 'one',
2 : 'two',
3 : 'three'}
counter = 1
# Find all anchor links and map to the next counter value.
for line in s:
if r'\anchor' in line:
d[line.split(r'\anchor ')[1]] = numbers[counter]
counter += 1
# Reform original string.
s = '\n'.join(s)
# Replace anchor links with appropriate counter value.
for key, value in d.items():
s = s.replace(key, value)
print s
Running this script results in the output
\anchor one
\image html foo.gif "My Caption"
\anchor two
\image html bar.gif "My Caption"
As Figure \ref one shows... Figure \ref two is...
It is trivial to modify the above script to read from standard input and write to standard out, so this can easily be used in conjunction with the INPUT_FILTER configuration file option.
One thing to note is that the dictionary numbers has to be extended to allow for more than three figures to be included. This is again trivial, but probably not easily scalable. Solutions for mapping from arbitrary numbers to the appropriate word(s) are available (see other questions on this site) so I haven't bothered to implement this here.
Related
I want to select logo image urls from a HTML string. I assume that the logo image URL will have text 'logo' somewhere in it's URL.
Need a regex that selects Image URLs from a given HTML string text. The logo URL will have text 'logo' in it's path.
/(https?:\/\/(?:www\.)?[\w+-_.0-9#\/]+logo.(?:png|jpg|jpeg))/i
["https://static.infragistics.com/marketing/Website/home/espn-logo.png", "https://static.infragistics.com/marketing/Website/home/mondelez-logo.png", "https://static.infragistics.com/marketing/Website/home/nielsen-logo.png", "https://static.infragistics.com/marketing/Website/home/united-logo.png", "https://static.infragistics.com/marketing/Website/home/merrill-lynch-logo.png", "https://static.infragistics.com/marketing/Website/home/dell-logo.png", "https://static.infragistics.com/marketing/Website/home/intel-logo.png", "https://static.infragistics.com/marketing/Website/home/prudential-logo.png", "https://static.infragistics.com/marketing/Website/home/mcdonalds-logo.png"]
The text logo can present anywhere in the URL.
Need a regex that picks Image URls which has text 'logo' in it.
Maybe, it would be a good idea to reduce our constraints in the expression, maybe without even word boundaries for logo, with some expression similar to:
(?i)^(?=.*logo)(?:https)?:\/\/\S+(?:png|jpe?g|gif|tiff)$
where,
(?=.*logo)
would simply check if there is a logo anywhere in the URL.
If we would just want to check the word logo, in the image names,
espn-logo.png
espn-logos.png
we would move our positive lookahead forward, after the last slash, for instance:
(?i)^(?:https)?:\/\/\S+\/(?=.*logo).*(?:png|jpe?g|gif|tiff)$
and our desired image extensions would go in this non-capturing group:
(?:png|jpe?g|gif|tiff|svg)
Test
re = /(?i)^(?=.*logo)(?:https)?:\/\/\S+(?:png|jpe?g|gif|tiff)$/s
str = 'https://static.infragistics.com/marketing/Website/home/espn-logo.png
https://static.infragistics.com/marketing/Website/home/mondelez-logo.gif
https://static.infragistics.com/marketing/Website/home/nielsen-logo.jpg
https://static.infragistics.com/marketing/Website/home/united-logo.jpeg
https://static.infragistics.com/marketing/Website/home/merrill-lynch-logo.PNG
https://static.infragistics.com/marketing/Website/home/dell-logo.TIFF
https://static.infragistics.com/marketing/Website/home/intel-logo.gif
https://static.infragistics.com/marketing/Website/home/prudential-logo.png
https://static.infragistics.com/marketing/Website/home/mcdonalds-logo.GIF
https://static.infragistics.com/marketing/Website/home/mcdonalds-alogo.GIF
https://static.infragistics.com/marketing/Website/home/mcdonalds-logos.GIF'
str.scan(re) do |match|
puts match.to_s
end
The expression is explained on the top right panel of regex101.com, if you wish to explore/simplify/modify it, and in this link, you can watch how it would match against some sample inputs, if you like.
RegEx Circuit
jex.im visualizes regular expressions:
Edit
For those cases that we have other instances of URLs, we would usually add more constraints for the edge cases, such as:
(?i)(?<=")\s*(?:https?)?:\/\/[^"]+\/(?=[^"]*logo)[^"]*(?:png|jpe?g|gif|tiff)\s*(?=")
DEMO
I guess maybe it would be easier to first collect the image URLs, then we would check if there is a \blogo\b in the image names. Otherwise, the expression might get complicated.
I am using ZPL for the first time to generate shipping labels. I am using a ruby-on-rails gem https://github.com/rjocoleman/labelary to ultimately turn the ZPL sting into a pdf. I want to create multiple pages, incrementing a variable for each page using a loop until enough pages have been created. Say the ZPL looks like this:
^XA
^FX Top section with company logo, name and address.
^CF0,60
^FO50,50^GB100,100,100^FS
^FO75,75^FR^GB100,100,100^FS
^FO88,88^GB50,50,50^FS
^FO220,50^FDInternational Shipping, Inc.^FS
^CF0,40
^FO220,100^FD1000 Shipping Lane^FS
^FO220,135^FDShelbyville TN 38102^FS
^FO220,170^FDUnited States (USA)^FS
^FO50,250^GB700,1,3^FS
^FX Second section with recipient address and permit information.
^CFA,30
^FO50,300^FDJohn Doe^FS
^FO50,340^FD100 Main Street^FS
^FO50,380^FDSpringfield TN 39021^FS
^FO50,420^FDUnited States (USA)^FS
^CFA,15
^FO600,300^GB150,150,3^FS
^FO638,340^FDPermit^FS
^FO638,390^FD123456^FS
^FO50,500^GB700,1,3^FS
^FX Third section with barcode.
^BY5,2,270
^FO175,550^BC^FD1234567890^FS
^FX Fourth section (the two boxes on the bottom).
^FO50,900^GB700,250,3^FS
^FO400,900^GB1,250,3^FS
^CF0,40
^FO100,960^FDShipping Ctr. X34B-1^FS
^FO100,1010^FDREF1 F00B47^FS
^FO100,1060^FDREF2 BL4H8^FS
^CF0,190
^FO485,965^FDCA^FS
^XZ
How can I add a page break to the end of the ZPL string, so the loop can create a new identical page after the first one (all in a single zpl string)?
Thanks in advance
If your pages are truly identical, you could just use the ^PQ command to set the number of copies you want to print (e.g. ^PQ3 to print three copies). This command must appear before the ^XZ command.
However if your pages aren't identical (maybe you have a sequence number or something), just start a new format by using a new ^XA command after your first page is done.
I am trying to add a a couple of authors to a report I am writing. Preferably, the second author would appear on a new line after the first. I know I can modify the template to add a new field or the multiple author example given in the Pandoc readme. However, I wonder if there is any character I can use to insert a new line between authors directly in the metablock. So far I have tried \newline, \\, | with newline and space, <br>, <div></div>, and making the author list a string with newline or double spaces between author names, but nothing has worked. My desired output is pdf.
The problem isn't in the YAML metadata formatting (for which there are numerous ways to have multiline strings), but that the LaTeX \author command strips the newlines. But for PDF output (with LaTeX) you can do:
---
title: mytitle
author: '\protect\parbox{\textwidth}{\protect\centering Author: 1\\ Author: 2\\ Author 3}'
---
body text
You can go with a simple list to achieve this.
---
title: 'Any title comes here'
author:
- Author One
- Author Two
---
Another way is to rely on the title block that has a slightly different syntax.
% Any title comes here
% author(s) (separated by semicolons)
% date
Find additional variants in the metadata-block section of the pandoc manual.
I'm using markdown for comments on my site and I want users to be able to create line breaks by pressing enter instead of space space enter (see this meta question for more details on this idea)
How can I do this in Ruby? You'd think Github Flavored Markdown would be exactly what I need, but (surprisingly), it's quite buggy.
Here's their implementation:
# in very clear cases, let newlines become <br /> tags
text.gsub!(/^[\w\<][^\n]*\n+/) do |x|
x =~ /\n{2}/ ? x : (x.strip!; x << " \n")
end
This logic requires that the line start with a \w for a linebreak at the end to create a <br>. The reason for this requirement is that you don't to mess with lists: (But see the edit below; I'm not even sure this makes sense)
* we don't want a <br>
* between these two list items
However, the logic breaks in these cases:
[some](http://google.com)
[links](http://google.com)
*this line is in italics*
another line
> the start of a blockquote!
another line
I.e., in all of these cases there should be a <br> at the end of the first line, and yet GFM doesn't add one
Oddly, this works correctly in the javascript version of GFM.
Does anyone have a working implementation of "new lines to <br>s" in Ruby?
Edit: It gets even more confusing!
If you check out Github's official Github Flavored Markdown repository, you'll find yet another newline to <br> regex!:
# in very clear cases, let newlines become <br /> tags
text.gsub!(/(\A|^$\n)(^\w[^\n]*\n)(^\w[^\n]*$)+/m) do |x|
x.gsub(/^(.+)$/, "\\1 ")
end
I have no clue what this regex means, but it doesn't do any better on the above test cases.
Also, it doesn't look like the "don't mess with lists" justification for requiring that lines start with word characters is valid to begin with. I.e., standard markdown list semantics don't change regardless of whether you add 2 trailing spaces. Here:
item 1
item 2
item 3
In the source of this question there are 2 trailing spaces after "item 1", and yet if you look at the HTML, there is no superfluous <br>
This leads me to think the best regex for converting newlines to <br>s is just:
text.gsub!(/^[^\n]+\n+/) do |x|
x =~ /\n{2}/ ? x : (x.strip!; x << " \n")
end
Thoughts?
I'm not sure if this will help, but I just use simple_format()
from ActionView::Helpers::TextHelper
ActionView simple_format
my_text = "Here is some basic text...\n...with a line break."
simple_format(my_text)
output => "<p>Here is some basic text...\n<br />...with a line break.</p>"
Even if it doesn't meet your specs, looking at the simple_format() source code .gsub! methods might help you out writing your own version of required markdown.
A little too late, but perhaps useful for other people. I've gotten it to work (but not thoroughly tested) by preprocessing the text using regular expressions, like so. It's hideous as a result of the lack of zero-width lookbehinds, but oh well.
# Append two spaces to a simple line, if it ends in newline, to render the
# markdown properly. Note: do not do this for lists, instead insert two newlines. Also, leave double newlines
# alone.
text.gsub! /^ ([\*\+\-]\s+|\d+\s+)? (.+?) (\ \ )? \r?\n (\r?\n|[\*\+\-]\s+|\d+\s+)? /xi do
full, pre, line, spaces, post = $~.to_a
if post != "\n" && pre.blank? && post.blank? && spaces.blank?
"#{pre}#{line} \n#{post}"
elsif pre.present? || post.present?
"#{pre}#{line}\n\n#{post}"
else
full
end
end
I'm using ruby and I'm trying to find a way to grab text in between the {start_grab_entries} and {end_grab_entries} like so:
{start_grab_entries}
i want to grab
the text that
you see here in
the middle
{end_grab_entries}
Something like so:
$1 => "i want to grab
the text that
you see here in
the middle"
So far, I tried this as my regular expression:
\{start_grab_entries}(.|\n)*\{end_grab_entries}
However, using $1, that gives me a blank. Do you know what I can do to grab that block of text in between the tags correctly?
There is a better way to allow the dot to match newlines (/m modifier):
regexp = /\{start_grab_entries\}(.*?)\{end_grab_entries\}/m
Also, make the * lazy by appending a ?, or you might match too much if more than one such section occurs in your input.
That said, the reason why you got a blank match is that you repeated the capturing group itself; therefore you only caught the last repetition (in this case, a \n).
It would have "worked" if you had put the capturing group outside of the repetition:
\{start_grab_entries\}((?:.|\n)*)\{end_grab_entries\}`
but, as said above, there is a better way to do that.
I'm adding this because often we're reading data from a file or data-stream where the range of lines we want are not all in memory at once. "Slurping" a file is discouraged if the data could exceed the available memory, something that easily happens in production corporate environments. This is how we'd grab lines between some boundary markers as the file is being scanned. It doesn't rely on regex, instead using Ruby's "flip-flop" .. operator:
#!/usr/bin/ruby
lines = []
DATA.each_line do |line|
lines << line if (line['{start_grab_entries}'] .. line['{end_grab_entries}'])
end
puts lines # << lines with boundary markers
puts
puts lines[1 .. -2] # << lines without boundary markers
__END__
this is not captured
{start_grab_entries}
i want to grab
the text that
you see here in
the middle
{end_grab_entries}
this is not captured either
Output of this code would look like:
{start_grab_entries}
i want to grab
the text that
you see here in
the middle
{end_grab_entries}
i want to grab
the text that
you see here in
the middle
string=<<EOF
blah
{start_grab_entries}
i want to grab
the text that
you see here in
the middle
{end_grab_entries}
blah
EOF
puts string.scan(/{start_grab_entries}(.*?){end_grab_entries}/m)