Hi Lex,

The patch has been updated to include an asciidoc.conf attribute in the 
[miscellaneous] section to control the deletion of a line with a missing 
simple attribute reference.

The Asciidoc configuration option is called 'attrdropline' and the default 
value is 'True' causing no change in current processing
of missing simple attribute references.  If the value is 'False', such a 
line will be emitted with the missing simple attribute reference unchanged 
and a warning message identifying the file name, line number, and simple 
attribute reference will be emitted as well.

The patch also includes a documentation update to doc/asciidoc.txt.

It has been tested using the current Asciidoc repository trunk.

Thank you.
Peg Russell

On Wednesday, March 6, 2013 7:28:06 PM UTC-6, Lex Trotman wrote:
>
> On 7 March 2013 12:09, Stargazer <[email protected] <javascript:>> 
> wrote: 
> > Hi, 
> > 
> > I have been applying this patch to Asciidoc for a couple of releases 
> now. It 
> > really has been a time saver and allows for more automation. I hope you 
> will 
> > consider it for permanent inclusion in Asciidoc. 
> > 
> > Summary: 
> > Rather than quietly deleting an entire line when a simple attribute 
> > reference is missing, --- more often just a fat-finger typo --- leave 
> the 
> > line alone and issue a warning message.  In large documents throwing 
> away a 
> > line without notice can be frustrating and time consuming. 
> > 
> > Patch: 
> > The patch (diff -u) has been tested on the current Asciidoc release, 
> 8.6.8, 
> > as well as the current trunk. 
> > 
> > Attached: 
> > 1. Patch 
> > 2. Small Asciidoc source example 
> > 3. Output from source 
> > 
>
> Hi Peg, 
>
> I think you can do similar in a configurable way with the existing 
> trace facilities, see 
> http://www.methods.co.nz/asciidoc/userguide.html#X82. 
>
> Certainly such a patch cannot be accepted without an option to enable 
> it, so that by default documents that mean to drop stuff don't have 
> their behaviour changed. 
>
> Cheers 
> Lex 
>
> > Thank you. 
> > Peg Russell 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "asciidoc" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to [email protected] <javascript:>. 
> > To post to this group, send email to [email protected]<javascript:>. 
>
> > Visit this group at http://groups.google.com/group/asciidoc?hl=en. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
> > 
> > 
>

-- 
You received this message because you are subscribed to the Google Groups 
"asciidoc" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/asciidoc?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


--- trunk/asciidoc.py	2013-03-07 03:30:52.000000000 -0600
+++ asciidoc.py	2013-03-07 05:17:46.000000000 -0600
@@ -1178,8 +1178,13 @@
         # Drop line if it contains  unsubstituted {name} references.
         skipped = re.search(r'(?su)\{[^\\\W][-\w]*?\}(?!\\)', line)
         if skipped:
-            trace('dropped line', line)
-            continue;
+            if config.attrdropline or line[0] == '<' or skipped.group(0) == '{zzzzz}' or skipped.group(0) == '{revnumber}' or skipped.group(0) == '{themedir}' or skipped.group(0) == '{stylesheet}' or skipped.group(0) == '{float}' or skipped.group(0) == '{headrows}' or skipped.group(0) == '{footrows}' or skipped.group(0) == '{attribution}':
+              trace('dropped line', line)
+              continue;
+            else:
+              result.append(line)
+              message.warning('undefined attribute: %s' % skipped.group(0))
+              continue;
         # Expand system attributes (eval has precedence).
         reos = [
             re.compile(r'(?su)\{(?P<action>eval):(?P<expr>.*?)\}(?!\\)'),
@@ -4520,6 +4525,7 @@
         self.tabsize = 8
         self.textwidth = 70             # DEPRECATED: Old tables only.
         self.newline = '\r\n'
+        self.attrdropline = True
         self.pagewidth = None
         self.pageunits = None
         self.outfilesuffix = ''
@@ -4828,6 +4834,15 @@
             except ValueError:
                 raise EAsciiDoc, 'illegal [miscellaneous] pagewidth entry'
 
+        if 'attrdropline' in d:
+            try:
+                if d['attrdropline'].lower() in ("yes", "true", "t", "1", "no", "false", "f", "0"):
+                  self.attrdropline = d['attrdropline'].lower() in ("yes", "true", "t", "1")
+                else:
+                  raise EAsciiDoc, 'non-boolean [miscellaneous] attrdropline entry'
+            except ValueError:
+                raise EAsciiDoc, 'illegal [miscellaneous] attrdropline entry'
+
         if 'pageunits' in d:
             self.pageunits = d['pageunits']
         if 'outfilesuffix' in d:
--- trunk/doc/asciidoc.txt	2013-03-07 03:06:28.000000000 -0600
+++ doc/asciidoc.txt	2013-03-07 12:55:36.000000000 -0600
@@ -1,4 +1,4 @@
-AsciiDoc User Guide
+/AsciiDoc User Guide
 ===================
 Stuart Rackham <[email protected]>
 :Author Initials: SJR
@@ -3838,6 +3838,17 @@
         These global table related options are documented in the
         <<X4,Table Configuration File Definitions>> sub-section.
 
+attrdropline::
+        The action of suppressing lines with undefined attributes may
+        be changed by setting this option to `False`, for example
+        `attrdropline=False`.  Defaults to `True`.  An option of
+        `False` will cause lines with undefined attributes to be
+        preserved in the output with the missing attribute unchanged
+        and a warning will be emittted that identifies the file name,
+        line number, and the undefined attribute.  When this option
+        is set to `True` or defaulted, the entire line will be
+        suppressed in the output without warning.
+
 NOTE: `[miscellaneous]` configuration file entries can be set using
 the asciidoc(1) `-a` (`--attribute`) command-line option.
 
@@ -4375,6 +4386,12 @@
 corresponding text value.  If the attribute is undefined the line
 containing the attribute is dropped.
 
+If the `attrdropline` entry in the configuration file
+`[miscellaneous]` section is set to `False`, then the line containing
+the undefined attribute is emitted with the undefined attribute
+unchanged, and a warning identifying the file name, line number, and
+the undefined attribute is emitted.
+
 There are three types of attribute reference: 'Simple', 'Conditional'
 and 'System'.
 
@@ -4394,6 +4411,12 @@
 attribute name is defined its text value is substituted otherwise the
 line containing the reference is dropped from the output.
 
+This may be overriden by setting the `attrdropline` entry in the
+configuration file `[miscellaneous]` section to `False` to emit the
+line containing the undefined attribute with the undefined attribute
+unchanged, and emit a warning that identifies the file name, line
+number, and the undefined attribute.
+
 Conditional Attribute References
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Additional parameters are used in conjunction with attribute names to

Reply via email to