draft-ietf-netmod-artwork-folding-02.txt   draft-ietf-netmod-artwork-folding-03.txt 
NETMOD Working Group K. Watsen NETMOD Working Group K. Watsen
Internet-Draft Watsen Networks Internet-Draft Watsen Networks
Intended status: Best Current Practice A. Farrel Intended status: Best Current Practice A. Farrel
Expires: October 8, 2019 Old Dog Consulting Expires: December 1, 2019 Old Dog Consulting
Q. Wu Q. Wu
Huawei Technologies Huawei Technologies
April 6, 2019 May 30, 2019
Handling Long Lines in Inclusions in Internet-Drafts and RFCs Handling Long Lines in Inclusions in Internet-Drafts and RFCs
draft-ietf-netmod-artwork-folding-02 draft-ietf-netmod-artwork-folding-03
Abstract Abstract
This document defines a simple and yet time-proven strategy for This document defines two strategies for handling long lines in
handling long lines in inclusions in internet drafts and RFCs using a width-bounded text content. One strategy is based on the historic
backslash ('\') character to indicate where line-folding has use of a single backslash ('\') character to indicate where line-
occurred. The strategy works on any text-based content, but is folding has occurred, with the continuation occurring with the first
primarily intended for a structured sequence of lines rather than for non-space (' ') character on the next line. The second strategy
two-dimensional imagery. The approach produces consistent results, extends the first strategy by adding a second backslash character to
regardless of the content, that is both self-documenting and enables identify where the continuation begins and thereby able to handle
automated reconstitution of the original content. cases not supported by the first strategy. Both strategies use a
self-describing header enabling automated reconstitution of the
original content.
Status of This Memo Status of This Memo
This Internet-Draft is submitted in full conformance with the This Internet-Draft is submitted in full conformance with the
provisions of BCP 78 and BCP 79. provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF). Note that other groups may also distribute Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet- working documents as Internet-Drafts. The list of current Internet-
Drafts is at https://datatracker.ietf.org/drafts/current/. Drafts is at https://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months Internet-Drafts are draft documents valid for a maximum of six months
and may be updated, replaced, or obsoleted by other documents at any and may be updated, replaced, or obsoleted by other documents at any
time. It is inappropriate to use Internet-Drafts as reference time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress." material or to cite them other than as "work in progress."
This Internet-Draft will expire on October 8, 2019. This Internet-Draft will expire on December 1, 2019.
Copyright Notice Copyright Notice
Copyright (c) 2019 IETF Trust and the persons identified as the Copyright (c) 2019 IETF Trust and the persons identified as the
document authors. All rights reserved. document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents Provisions Relating to IETF Documents
(https://trustee.ietf.org/license-info) in effect on the date of (https://trustee.ietf.org/license-info) in effect on the date of
publication of this document. Please review these documents publication of this document. Please review these documents
carefully, as they describe your rights and restrictions with respect carefully, as they describe your rights and restrictions with respect
to this document. Code Components extracted from this document must to this document. Code Components extracted from this document must
include Simplified BSD License text as described in Section 4.e of include Simplified BSD License text as described in Section 4.e of
the Trust Legal Provisions and are provided without warranty as the Trust Legal Provisions and are provided without warranty as
described in the Simplified BSD License. described in the Simplified BSD License.
Table of Contents Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3
2. Applicability Statement . . . . . . . . . . . . . . . . . . . 3 2. Applicability Statement . . . . . . . . . . . . . . . . . . . 4
3. Requirements Language . . . . . . . . . . . . . . . . . . . . 4 3. Requirements Language . . . . . . . . . . . . . . . . . . . . 4
4. Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4. Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.1. Automated Folding of Long Lines in Text Content . . . . . 4 4.1. Automated Folding of Long Lines in Text Content . . . . . 4
4.2. Automated Reconstitution of the Original Text Content . . 4 4.2. Automated Reconstitution of the Original Text Content . . 5
5. Limitations . . . . . . . . . . . . . . . . . . . . . . . . . 5 5. Limitations . . . . . . . . . . . . . . . . . . . . . . . . . 5
5.1. Not Recommended for Graphical Artwork . . . . . . . . . . 5 5.1. Not Recommended for Graphical Artwork . . . . . . . . . . 5
5.2. Doesn't Work as Well as Format-Specific Options . . . . . 5 5.2. Doesn't Work as Well as Format-Specific Options . . . . . 5
6. Two Folding Strategies . . . . . . . . . . . . . . . . . . . 5 6. Two Folding Strategies . . . . . . . . . . . . . . . . . . . 6
6.1. Comparison . . . . . . . . . . . . . . . . . . . . . . . 6 6.1. Comparison . . . . . . . . . . . . . . . . . . . . . . . 6
6.2. Recommendation . . . . . . . . . . . . . . . . . . . . . 6 6.2. Recommendation . . . . . . . . . . . . . . . . . . . . . 6
7. The Single Backslash Strategy ('\') . . . . . . . . . . . . . 6 7. The Single Backslash Strategy ('\') . . . . . . . . . . . . . 6
7.1. Folded Structure . . . . . . . . . . . . . . . . . . . . 6 7.1. Folded Structure . . . . . . . . . . . . . . . . . . . . 6
7.1.1. Header . . . . . . . . . . . . . . . . . . . . . . . 6 7.1.1. Header . . . . . . . . . . . . . . . . . . . . . . . 7
7.1.2. Body . . . . . . . . . . . . . . . . . . . . . . . . 7 7.1.2. Body . . . . . . . . . . . . . . . . . . . . . . . . 7
7.2. Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 7 7.2. Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 7
7.2.1. Folding . . . . . . . . . . . . . . . . . . . . . . . 7 7.2.1. Folding . . . . . . . . . . . . . . . . . . . . . . . 7
7.2.2. Unfolding . . . . . . . . . . . . . . . . . . . . . . 8 7.2.2. Unfolding . . . . . . . . . . . . . . . . . . . . . . 9
8. The Double Backslash Strategy ('\\') . . . . . . . . . . . . 9 8. The Double Backslash Strategy ('\\') . . . . . . . . . . . . 9
8.1. Folded Structure . . . . . . . . . . . . . . . . . . . . 9 8.1. Folded Structure . . . . . . . . . . . . . . . . . . . . 9
8.1.1. Header . . . . . . . . . . . . . . . . . . . . . . . 9 8.1.1. Header . . . . . . . . . . . . . . . . . . . . . . . 9
8.1.2. Body . . . . . . . . . . . . . . . . . . . . . . . . 9 8.1.2. Body . . . . . . . . . . . . . . . . . . . . . . . . 10
8.2. Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 10 8.2. Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 10
8.2.1. Folding . . . . . . . . . . . . . . . . . . . . . . . 10 8.2.1. Folding . . . . . . . . . . . . . . . . . . . . . . . 10
8.2.2. Unfolding . . . . . . . . . . . . . . . . . . . . . . 11 8.2.2. Unfolding . . . . . . . . . . . . . . . . . . . . . . 11
9. Examples . . . . . . . . . . . . . . . . . . . . . . . . . . 12 9. Examples . . . . . . . . . . . . . . . . . . . . . . . . . . 12
9.1. Example Showing Boundary Conditions . . . . . . . . . . . 12 9.1. Example Showing Boundary Conditions . . . . . . . . . . . 12
9.1.1. Using '\' . . . . . . . . . . . . . . . . . . . . . . 12 9.1.1. Using '\' . . . . . . . . . . . . . . . . . . . . . . 12
9.1.2. Using '\\' . . . . . . . . . . . . . . . . . . . . . 12 9.1.2. Using '\\' . . . . . . . . . . . . . . . . . . . . . 13
9.2. Example Showing Multiple Wraps of a Single Line . . . . . 13 9.2. Example Showing Multiple Wraps of a Single Line . . . . . 13
9.2.1. Using '\' . . . . . . . . . . . . . . . . . . . . . . 13 9.2.1. Using '\' . . . . . . . . . . . . . . . . . . . . . . 13
9.2.2. Using '\\' . . . . . . . . . . . . . . . . . . . . . 13 9.2.2. Using '\\' . . . . . . . . . . . . . . . . . . . . . 13
9.3. Example Showing Smart Folding . . . . . . . . . . . . . . 13 9.3. Example Showing Smart Folding . . . . . . . . . . . . . . 13
9.3.1. Using '\' . . . . . . . . . . . . . . . . . . . . . . 13 9.3.1. Using '\' . . . . . . . . . . . . . . . . . . . . . . 14
9.3.2. Using '\\' . . . . . . . . . . . . . . . . . . . . . 14 9.3.2. Using '\\' . . . . . . . . . . . . . . . . . . . . . 15
10. Security Considerations . . . . . . . . . . . . . . . . . . . 15
10. Security Considerations . . . . . . . . . . . . . . . . . . . 16
11. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 16 11. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 16
12. References . . . . . . . . . . . . . . . . . . . . . . . . . 16 12. References . . . . . . . . . . . . . . . . . . . . . . . . . 16
12.1. Normative References . . . . . . . . . . . . . . . . . . 16 12.1. Normative References . . . . . . . . . . . . . . . . . . 16
12.2. Informative References . . . . . . . . . . . . . . . . . 16 12.2. Informative References . . . . . . . . . . . . . . . . . 16
Appendix A. POSIX Shell Script . . . . . . . . . . . . . . . . . 17 Appendix A. POSIX Shell Script . . . . . . . . . . . . . . . . . 18
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 23 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 25
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 23 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 25
1. Introduction 1. Introduction
[RFC7994] sets out the requirements for plain-text RFCs and states [RFC7994] sets out the requirements for plain-text RFCs and states
that each line of an RFC (and hence of an Internet-Draft) must be that each line of an RFC (and hence of an Internet-Draft) must be
limited to 72 characters followed by the character sequence that limited to 72 characters followed by the character sequence that
denotes an end-of-line (EOL). denotes an end-of-line (EOL).
Internet-Drafts and RFCs often include example text or code Internet-Drafts and RFCs often include example text or code
fragments. Many times the example text or code exceeds the 72 fragments. Many times the example text or code exceeds the 72
character line-length limit. The `xml2rfc` utility does not attempt character line-length limit. The `xml2rfc` utility does not attempt
to wrap the content of such inclusions, simply issuing a warning to wrap the content of such inclusions, simply issuing a warning
whenever lines exceed 69 characters. According to the RFC Editor, whenever lines exceed 69 characters. According to the RFC Editor,
there is currently no convention in place for how to handle long there is currently no convention in place for how to handle long
lines in such inclusions, other than advising authors to clearly lines in such inclusions, other than advising authors to clearly
indicate what manipulation has occurred. indicate what manipulation has occurred.
This document introduces a simple and yet time-proven strategy for This document defines two strategies for handling long lines in
handling long lines using a backslash ('\') character to indicate width-bounded text content. One strategy is based on the historic
where line-folding has occurred. The strategy works on any text use of a single backslash ('\') character to indicate where line-
based inclusion, but is primarily intended for a structured sequence folding has occurred, with the continuation occurring with the first
of lines, such as would be referenced by the <sourcecode> element non-space (' ') character on the next line. The second strategy
defined in Section 2.48 of [RFC7991], rather than for two-dimensional extends the first strategy by adding a second backslash character to
imagery, such as would be referenced by the <artwork> element defined identify where the continuation begins and thereby able to handle
in Section 2.5 of [RFC7991]. The approach produces consistent cases not supported by the first strategy. Both strategies use a
results, regardless of the content, that is both self-documenting and self-describing header enabling automated reconstitution of the
enables automated reconstitution of the original content. original content.
The strategies defined in this document work on any text content, but
are primarily intended for a structured sequence of lines, such as
would be referenced by the <sourcecode> element defined in
Section 2.48 of [RFC7991], rather than for two-dimensional imagery,
such as would be referenced by the <artwork> element defined in
Section 2.5 of [RFC7991].
Note that text files are represented as lines having their first Note that text files are represented as lines having their first
character in column 1, and a line length of N where the last character in column 1, and a line length of N where the last
character is in the Nth column and is immediately followed by an end character is in the Nth column and is immediately followed by an end
of line character sequence. of line character sequence.
2. Applicability Statement 2. Applicability Statement
The format and algorithm defined in this document may be used in any The formats and algorithms defined in this document may be used in
context, whether for IETF documents or in other situations where any context, whether for IETF documents or in other situations where
structured folding is desired. structured folding is desired.
Within the IETF, this work primarily targets the xml2rfc v3 Within the IETF, this work primarily targets the xml2rfc v3
<sourcecode> element (Section 2.48 of [RFC7991]) and the xml2rfc v2 <sourcecode> element (Section 2.48 of [RFC7991]) and the xml2rfc v2
<artwork> element (Section 2.5 of [RFC7749]) that, for lack of a <artwork> element (Section 2.5 of [RFC7749]) that, for lack of a
better option, is currently used for both source code and artwork. better option, is currently used for both source code and artwork.
This work may be also be used for the xml2rfc v3 <artwork> element This work may be also be used for the xml2rfc v3 <artwork> element
(Section 2.5 of [RFC7991]) but, as described in Section 5.1, it is (Section 2.5 of [RFC7991]) but, as described in Section 5.1, it is
generally not recommended. generally not recommended.
3. Requirements Language 3. Requirements Language
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
"OPTIONAL" in this document are to be interpreted as described in BCP "OPTIONAL" in this document are to be interpreted as described in BCP
14 [RFC2119] [RFC8174] when, and only when, they appear in all 14 [RFC2119] [RFC8174] when, and only when, they appear in all
skipping to change at page 4, line 42 skipping to change at page 5, line 7
effort and errors resulting from manual processing. effort and errors resulting from manual processing.
Similarly, dynamically generated output (e.g., tree diagrams) must Similarly, dynamically generated output (e.g., tree diagrams) must
also be modified, if necessary, in order for the resulting document also be modified, if necessary, in order for the resulting document
to satisfy the line length limits. When needed, this effort again to satisfy the line length limits. When needed, this effort again
SHOULD be automated to reduce effort and errors resulting from manual SHOULD be automated to reduce effort and errors resulting from manual
processing. processing.
4.2. Automated Reconstitution of the Original Text Content 4.2. Automated Reconstitution of the Original Text Content
Automated reconstitution of the original content is needed to support Automated reconstitution of the exact original text content is needed
validation of text-based inclusions extracted from documents. YANG to support validation of text-based content extracted from documents.
[RFC7950] modules are already extracted from Internet-Drafts and
validated as part of the draft-submission process. Additionally, For instance, already YANG [RFC7950] modules are extracted from
there has been some discussion regarding needing to also validate Internet-Drafts and validated as part of the draft-submission
instance examples (i.e., XML/JSON documents) contained within process. Additionally, the desire to validate instance examples
Internet-Drafts ([yang-doctors-thread]). Thus, it SHOULD be possible (i.e., XML/JSON documents) contained within Internet-Drafts has been
to mechanically reconstitute the original text content in order to discussed ([yang-doctors-thread]).
utilize such tooling.
5. Limitations 5. Limitations
5.1. Not Recommended for Graphical Artwork 5.1. Not Recommended for Graphical Artwork
While the solution presented in this document will work on any kind While the solution presented in this document works on any kind of
of text-based content, it is most useful on content that represents text-based content, it is most useful on content that represents
source code (XML, JSON, etc.) or, more generally, on content that has source code (XML, JSON, etc.) or, more generally, on content that has
not been laid out in two dimensions (e.g., diagrams). not been laid out in two dimensions (e.g., diagrams).
Fundamentally, the issue is whether the text content remains readable Fundamentally, the issue is whether the text content remains readable
once folded. Text content that is unpredictable is especially once folded. Text content that is unpredictable is especially
susceptible to looking bad when folded; falling into this category susceptible to looking bad when folded; falling into this category
are most UML diagrams, YANG tree diagrams, and ASCII art in general. are most UML diagrams, YANG tree diagrams, and ASCII art in general.
It is NOT RECOMMENDED to use the solution presented in this document It is NOT RECOMMENDED to use the solution presented in this document
on graphical artwork. on graphical artwork.
skipping to change at page 5, line 39 skipping to change at page 5, line 50
For instance, both the `pyang` and `yanglint` utilities have the For instance, both the `pyang` and `yanglint` utilities have the
command line option "--tree-line-length" that can be used to indicate command line option "--tree-line-length" that can be used to indicate
a desired maximum line length for when generating tree diagrams a desired maximum line length for when generating tree diagrams
[RFC8340]. [RFC8340].
In another example, some source formats (e.g., YANG [RFC7950]) allow In another example, some source formats (e.g., YANG [RFC7950]) allow
any quoted string to be broken up into substrings separated by a any quoted string to be broken up into substrings separated by a
concatenation character (e.g., '+'), any of which can be on a concatenation character (e.g., '+'), any of which can be on a
different line. different line.
In yet another example, some languages allow factoring blocks of code
into call outs, such as functions. Using such call outs is
especially helpful when in some deeply-nested code, as they typically
reset the indentation back to the first column.
It is RECOMMENDED that authors do as much as possible within the It is RECOMMENDED that authors do as much as possible within the
selected format to avoid long lines. selected format to avoid long lines.
6. Two Folding Strategies 6. Two Folding Strategies
This document defines two nearly identical strategies for folding This document defines two nearly identical strategies for folding
text-based content. text-based content.
The Single Backslash Strategy ('\'): Uses a backslash ('\') The Single Backslash Strategy ('\'): Uses a backslash ('\')
character at the end of the line where folding occurs, and character at the end of the line where folding occurs, and
assumes that the continuation begins at the first non- assumes that the continuation begins at the character that is
whitespace character on the following line. not a space character (' ') on the following line.
The Double Backslash Strategy ('\\'): Uses a backslash ('\') The Double Backslash Strategy ('\\'): Uses a backslash ('\')
character at the end of the line where folding occurs, and character at the end of the line where folding occurs, and
assumes that the continuation begins after a second backslash assumes that the continuation begins after a second backslash
('\') character on the following line. ('\') character on the following line.
6.1. Comparison 6.1. Comparison
The first strategy produces more readable output, however it is The first strategy produces more readable output, however it is
significantly more likely to encounter unfoldable input (e.g., there significantly more likely to encounter unfoldable input (e.g., there
is exists a line anywhere in the input ending with a backslash exists a line anywhere in the input ending with a backslash
character, or there exists a long line containing only space and character, or there exists a long line containing only space
backslash characters) and, for long lines that can be folded, characters) and, for long lines that can be folded, automation
automation implementations are likely to encounter scenarios that implementations may encounter scenarios that will produce errors
will produce errors without special care. without special care.
The second strategy produces less readable output, but is unlikely to The second strategy produces less readable output, but is unlikely to
encounter unfoldable input, there are no long lines that cannot be encounter unfoldable input, there are no long lines that cannot be
folded, and no special care is required for when folding a long line. folded, and no special care is required for when folding a long line.
6.2. Recommendation 6.2. Recommendation
It is RECOMMENDED for implementations to first attempt to fold It is RECOMMENDED for implementations to first attempt to fold
content using the single backslash strategy and, only in the unlikely content using the single backslash strategy and, only in the unlikely
event that it cannot fold the input or the folding logic is unable to event that it cannot fold the input or the folding logic is unable to
skipping to change at page 7, line 24 skipping to change at page 7, line 34
The character encoding is the same as described in Section 2 of The character encoding is the same as described in Section 2 of
[RFC7994], except that, per [RFC7991], tab characters are prohibited. [RFC7994], except that, per [RFC7991], tab characters are prohibited.
Lines that have a backslash ('\') occurring as the last character in Lines that have a backslash ('\') occurring as the last character in
a line are considered "folded". a line are considered "folded".
Really long lines may be folded multiple times. Really long lines may be folded multiple times.
7.2. Algorithm 7.2. Algorithm
This section describes the process for folding and unfolding long This section describes a process for folding and unfolding long lines
lines when they are encountered in a single instance of text content. when they are encountered in text content.
It is assumed that another process inserts/extracts the individual
text content instances to/from an Internet-Draft or RFC. For
example, the `xiax` utility [xiax] does this.
7.2.1. Folding The steps are complete, but implementations MAY achieve the same
result in other ways.
Folding is assumed to be automated although authors may perform the When a larger document contains multiple instances of text content
folding steps manually. that may need to be folded or unfolded, another process must insert/
extract the individual text content instances to/from the larger
document prior to utilizing the algorithms described in this section.
For example, the `xiax` utility [xiax] does this.
Determine the desired maximum line length from input to the automated 7.2.1. Folding
line-wrapping process, such as from a command line parameter. If no
value is explicitly specified, the value "69" SHOULD be used. Determine the desired maximum line length from input to the line-
wrapping process, such as from a command line parameter. If no value
is explicitly specified, the value "69" SHOULD be used.
Ensure that the desired maximum line length is not less than the Ensure that the desired maximum line length is not less than the
minimum header, which is 46 characters. If the desired maximum line minimum header, which is 45 characters. If the desired maximum line
length is less than this minimum, exit (this text-based content length is less than this minimum, exit (this text-based content
cannot be folded). cannot be folded).
Scan the text content for horizontal tab characters. If any Scan the text content for horizontal tab characters. If any
horizontal tab characters appear, either resolve them to space horizontal tab characters appear, either resolve them to space
characters or exit, forcing the input provider to convert them to characters or exit, forcing the input provider to convert them to
space characters themselves first. space characters themselves first.
Scan the text content to see if any line exceeds the desired maximum. Scan the text content to ensure at least one line exceeds the desired
If no line exceeds the desired maximum, exit (this text content does maximum. If no line exceeds the desired maximum, exit (this text
not need to be folded). content does not need to be folded).
Scan the text content to ensure no existing lines already end with a Scan the text content to ensure no existing lines already end with a
backslash ('\') character, as this would lead to an ambiguous result. backslash ('\') character, as this would lead to an ambiguous result.
If such a line is found, exit (this text content cannot be folded). If such a line is found, exit (this text content cannot be folded).
If this text content needs to and can be folded, insert the header If this text content needs to and can be folded, insert the header
described in Section 7.1.1, ensuring that any additional printable described in Section 7.1.1, ensuring that any additional printable
characters surrounding the header does not result in a line exceeding characters surrounding the header does not result in a line exceeding
the desired maximum.. the desired maximum.
For each line in the text content, from top-to-bottom, if the line For each line in the text content, from top-to-bottom, if the line
exceeds the desired maximum, then fold the line by: exceeds the desired maximum, then fold the line by:
1. Determine where the fold will occur. This location MUST be 1. Determine where the fold will occur. This location MUST be
before or at the desired maximum column, and MUST NOT precede a before or at the desired maximum column, and MUST NOT be on top
space (' ') character. of a space (' ') character. If no such location can be found,
then exit (this text content cannot be folded)
2. At the location where the fold is to occur, insert a backslash 2. At the location where the fold is to occur, insert a backslash
('\') character followed by the end of line character sequence. ('\') character followed by the end of line character sequence.
3. On the following line, insert any number of space (' ') 3. On the following line, insert any number of space (' ')
characters. characters.
The result of the previous operation is that the next line starts The result of the previous operation is that the next line starts
with an arbitrary number of space (' ') characters, followed by the with an arbitrary number of space (' ') characters, followed by the
character that was previously occupying the position where the fold character that was previously occupying the position where the fold
skipping to change at page 8, line 42 skipping to change at page 9, line 10
Continue in this manner until reaching the end of the text content. Continue in this manner until reaching the end of the text content.
Note that this algorithm naturally addresses the case where the Note that this algorithm naturally addresses the case where the
remainder of a folded line is still longer than the desired maximum, remainder of a folded line is still longer than the desired maximum,
and hence needs to be folded again, ad infinitum. and hence needs to be folded again, ad infinitum.
The process described in this section is illustrated by the The process described in this section is illustrated by the
"fold_it_1()" function in Appendix A. "fold_it_1()" function in Appendix A.
7.2.2. Unfolding 7.2.2. Unfolding
All unfolding is assumed to be automated, although a reader will
mentally perform the act of unfolding the text to understand the true
nature of the original text content.
Scan the beginning of the text content for the header described in Scan the beginning of the text content for the header described in
Section 7.1.1. If the header is not present, starting on the first Section 7.1.1. If the header is not present, starting on the first
line of the text content, exit (this text contents does not need to line of the text content, exit (this text contents does not need to
be unfolded). be unfolded).
Remove the 2-line header from the text content. Remove the 2-line header from the text content.
For each line in the text content, from top-to-bottom, if the line For each line in the text content, from top-to-bottom, if the line
has a backslash ('\') character immediately followed by the end of has a backslash ('\') character immediately followed by the end of
line character sequence, then the line can be unfolded. Remove the line character sequence, then the line can be unfolded. Remove the
skipping to change at page 10, line 7 skipping to change at page 10, line 19
Lines that have a backslash ('\') occurring as the last character in Lines that have a backslash ('\') occurring as the last character in
a line immediately followed by the end of line character sequence, a line immediately followed by the end of line character sequence,
when the subsequent line starts with a backslash ('\') as the first when the subsequent line starts with a backslash ('\') as the first
non-space (' ') character, are considered "folded". non-space (' ') character, are considered "folded".
Really long lines may be folded multiple times. Really long lines may be folded multiple times.
8.2. Algorithm 8.2. Algorithm
This section describes the process for folding and unfolding long This section describes a process for folding and unfolding long lines
lines when they are encountered in a single instance of text content. when they are encountered in text content.
It is assumed that another process inserts/extracts the individual
text content instances to/from an Internet-Draft or RFC. For
example, the `xiax` utility [xiax] does this.
8.2.1. Folding The steps are complete, but implementations MAY achieve the same
result in other ways.
Folding is assumed to be automated, although authors may perform the When a larger document contains multiple instances of text content
folding steps manually. that may need to be folded or unfolded, another process must insert/
extract the individual text content instances to/from the larger
document prior to utilizing the algorithms described in this section.
For example, the `xiax` utility [xiax] does this.
Determine the desired maximum line length from input to the automated 8.2.1. Folding
line-wrapping process, such as from a command line parameter. If no
value is explicitly specified, the value "69" SHOULD be used. Determine the desired maximum line length from input to the line-
wrapping process, such as from a command line parameter. If no value
is explicitly specified, the value "69" SHOULD be used.
Ensure that the desired maximum line length is not less than the Ensure that the desired maximum line length is not less than the
minimum header, which is 45 characters. If the desired maximum line minimum header, which is 46 characters. If the desired maximum line
length is less than this minimum, exit (this text-based content length is less than this minimum, exit (this text-based content
cannot be folded). cannot be folded).
Scan the text content for horizontal tab characters. If any Scan the text content for horizontal tab characters. If any
horizontal tab characters appear, either resolve them to space horizontal tab characters appear, either resolve them to space
characters or exit, forcing the input provider to convert them to characters or exit, forcing the input provider to convert them to
space characters themselves first. space characters themselves first.
Scan the text content to see if any line exceeds the desired maximum. Scan the text content to see if any line exceeds the desired maximum.
If no line exceeds the desired maximum, exit (this text content does If no line exceeds the desired maximum, exit (this text content does
not need to be folded). not need to be folded).
Scan the text content to ensure no existing lines already end with a Scan the text content to ensure no existing lines already end with a
backslash ('\') character while the subsequent line starts with a backslash ('\') character while the subsequent line starts with a
backslash ('\') character as the first non-space (' ') character, as backslash ('\') character as the first non-space (' ') character, as
this would lead to an ambiguous result. If such a line is found, this could lead to an ambiguous result. If such a line is found, and
exit (this text content cannot be folded). its width is less than the desired maximum, then it SHOULD be flagged
for forced folding (folding even though unnecessary). If the folding
implementation doesn't support forced foldings, it MUST exit.
If this text content needs to and can be folded, insert the header If this text content needs to and can be folded, insert the header
described in Section 8.1.1, ensuring that any additional printable described in Section 8.1.1, ensuring that any additional printable
characters surrounding the header does not result in a line exceeding characters surrounding the header does not result in a line exceeding
the desired maximum.. the desired maximum.
For each line in the text content, from top-to-bottom, if the line For each line in the text content, from top-to-bottom, if the line
exceeds the desired maximum, then fold the line by: exceeds the desired maximum, or requires a forced folding, then fold
the line by:
1. Determine where the fold will occur. This location MUST be 1. Determine where the fold will occur. This location MUST be
before or at the desired maximum column. before or at the desired maximum column.
2. At the location where the fold is to occur, insert a first 2. At the location where the fold is to occur, insert a first
backslash ('\') character followed by the end of line character backslash ('\') character followed by the end of line character
sequence. sequence.
3. On the following line, insert any number of space (' ') 3. On the following line, insert any number of space (' ')
characters followed by a second backslash ('\') character. characters followed by a second backslash ('\') character.
skipping to change at page 11, line 27 skipping to change at page 11, line 44
Continue in this manner until reaching the end of the text content. Continue in this manner until reaching the end of the text content.
Note that this algorithm naturally addresses the case where the Note that this algorithm naturally addresses the case where the
remainder of a folded line is still longer than the desired maximum, remainder of a folded line is still longer than the desired maximum,
and hence needs to be folded again, ad infinitum. and hence needs to be folded again, ad infinitum.
The process described in this section is illustrated by the The process described in this section is illustrated by the
"fold_it_2()" function in Appendix A. "fold_it_2()" function in Appendix A.
8.2.2. Unfolding 8.2.2. Unfolding
All unfolding is assumed to be automated although a reader will
mentally perform the act of unfolding the text to understand the true
nature of the original text content.
Scan the beginning of the text content for the header described in Scan the beginning of the text content for the header described in
Section 8.1.1. If the header is not present, starting on the first Section 8.1.1. If the header is not present, starting on the first
line of the text content, exit (this text content does not need to be line of the text content, exit (this text content does not need to be
unfolded). unfolded).
Remove the 2-line header from the text content. Remove the 2-line header from the text content.
For each line in the text content, from top-to-bottom, if the line For each line in the text content, from top-to-bottom, if the line
has a backslash ('\') character immediately followed by the end of has a backslash ('\') character immediately followed by the end of
line character sequence, and if the next line has a backslash ('\') line character sequence, and if the next line has a backslash ('\')
skipping to change at page 17, line 8 skipping to change at page 18, line 8
<https://pypi.org/project/xiax/>. <https://pypi.org/project/xiax/>.
[yang-doctors-thread] [yang-doctors-thread]
"[yang-doctors] automating yang doctor reviews", "[yang-doctors] automating yang doctor reviews",
<https://mailarchive.ietf.org/arch/msg/yang-doctors/ <https://mailarchive.ietf.org/arch/msg/yang-doctors/
DCfBqgfZPAD7afzeDFlQ1Xm2X3g>. DCfBqgfZPAD7afzeDFlQ1Xm2X3g>.
Appendix A. POSIX Shell Script Appendix A. POSIX Shell Script
This non-normative appendix section includes a shell script that can This non-normative appendix section includes a shell script that can
both fold and unfold text content. Note that this script is applied both fold and unfold text content using both the single and double
only to single text content instances. backslash strategies described in Section 7 and Section 8
respectively.
This script is intended to be applied to a single text content
instance. If it is desired to fold or unfold test content instances
within a larger document (e.g., an Internet draft or RFC), then
another tool must be used to extract the content from the larger
document before utilizing this script.
For readability purposes, this script forces the minimally supported
line length to be eight characters longer than the raw header text
defined in Section 7.1.1 and Section 8.1.1 so as to ensure that the
header can be wrapped by a space (' ') character and three equal
('=') characters on each side of the raw header text.
This script does not implement the "forced folding" logic described
in Section 8.2.1. In such cases the script will exit with the
message:
Error: infile has a line ending with a '\\' character
followed by a '\\' character as the first non-space
character on the next line. This file cannot be folded.
Shell-level end-of-line backslash ('\') characters have been
purposely added to the script so as to ensure that the script is
itself not folded in this document, thus simplify the ability to
copy/paste the script for local use. As should be evident by the
lack of the mandatory header described in Section 7.1.1, these
backslashes do not designate a folded line, such as described in
Section 7.
<CODE BEGINS>
#!/bin/bash --posix # must be `bash` (not `sh`) #!/bin/bash --posix # must be `bash` (not `sh`)
print_usage() { print_usage() {
echo echo
echo "Folds the text file, only if needed, at the specified" echo "Folds the text file, only if needed, at the specified"
echo "column, according to BCP XX." echo "column, according to BCP XX."
echo echo
echo "Usage: $0 [-s <strategy>] [-c <col>] [-r] -i <infile>" echo "Usage: $0 [-s <strategy>] [-c <col>] [-r] -i <infile>"
echo " -o <outfile>" echo " -o <outfile>"
skipping to change at page 17, line 44 skipping to change at page 19, line 26
strategy=0 # auto strategy=0 # auto
debug=0 debug=0
reversed=0 reversed=0
infile="" infile=""
outfile="" outfile=""
maxcol=69 # default, may be overridden by param maxcol=69 # default, may be overridden by param
hdr_txt_1="NOTE: '\\' line wrapping per BCP XX (RFC XXXX)" hdr_txt_1="NOTE: '\\' line wrapping per BCP XX (RFC XXXX)"
hdr_txt_2="NOTE: '\\\\' line wrapping per BCP XX (RFC XXXX)" hdr_txt_2="NOTE: '\\\\' line wrapping per BCP XX (RFC XXXX)"
equal_chars="==============================================" equal_chars="=============================================="
space_chars=" " space_chars=" "
temp_dir=""
fold_it_1() { fold_it_1() {
# ensure input file doesn't contain the fold-sequence already # ensure input file doesn't contain the fold-sequence already
pcregrep -M "\\\\\n" $infile >> /dev/null 2>&1 pcregrep -M "\\\\\n" $infile >> /dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo echo
echo "Error1: infile $infile has a line ending with a '\\'" echo "Error: infile $infile has a line ending with a '\\'"
echo "character. This file cannot be folded." echo "character. This file cannot be folded."
echo echo
return 1 return 1
fi fi
# stash some vars # stash some vars
testcol=`expr "$maxcol" + 1` testcol=`expr "$maxcol" + 1`
foldcol=`expr "$maxcol" - 1` # for the inserted '\' char foldcol=`expr "$maxcol" - 1` # for the inserted '\' char
# ensure input file doesn't contain whitespace on the fold column # ensure input file doesn't contain whitespace on the fold column
grep "^.\{$foldcol\} " $infile >> /dev/null 2>&1 grep "^.\{$foldcol\} " $infile >> /dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo echo
echo "Error: infile has a space character occuring after the" echo "Error: infile has a space character occuring on the"
echo "folding column. This file cannot be folded." echo "folding column. This file cannot be folded."
echo echo
return 1 return 1
fi fi
# center header text # center header text
length=`expr ${#hdr_txt_1} + 2` length=`expr ${#hdr_txt_1} + 2`
left_sp=`expr \( "$maxcol" - "$length" \) / 2` left_sp=`expr \( "$maxcol" - "$length" \) / 2`
right_sp=`expr "$maxcol" - "$length" - "$left_sp"` right_sp=`expr "$maxcol" - "$length" - "$left_sp"`
header=`printf "%.*s %s %.*s" "$left_sp" "$equal_chars"\ header=`printf "%.*s %s %.*s" "$left_sp" "$equal_chars"\
"$hdr_txt_1" "$right_sp" "$equal_chars"` "$hdr_txt_1" "$right_sp" "$equal_chars"`
# generate outfile # generate outfile
echo "$header" > $outfile echo "$header" > $outfile
echo "" >> $outfile echo "" >> $outfile
skipping to change at page 18, line 38 skipping to change at page 20, line 21
# generate outfile # generate outfile
echo "$header" > $outfile echo "$header" > $outfile
echo "" >> $outfile echo "" >> $outfile
gsed "/.\{$testcol\}/s/\(.\{$foldcol\}\)/\1\\\\\n/g"\ gsed "/.\{$testcol\}/s/\(.\{$foldcol\}\)/\1\\\\\n/g"\
< $infile >> $outfile < $infile >> $outfile
return 0 return 0
} }
fold_it_2() { fold_it_2() {
if [ "$temp_dir" == "" ]; then
temp_dir=`mktemp -d`
fi
# ensure input file doesn't contain the fold-sequence already # ensure input file doesn't contain the fold-sequence already
pcregrep -M "\\\\\n[\ ]*\\\\" $infile >> /dev/null 2>&1 pcregrep -M "\\\\\n[\ ]*\\\\" $infile >> /dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo echo
echo "Error2: infile has a line ending with a '\\' character" echo "Error: infile has a line ending with a '\\' character"
echo "followed by a '\\' character as the first non-space" echo "followed by a '\\' character as the first non-space"
echo "character on the next line. This file cannot be folded." echo "character on the next line. This file cannot be folded."
echo echo
return 1 return 1
fi fi
# center header text # center header text
length=`expr ${#hdr_txt_2} + 2` length=`expr ${#hdr_txt_2} + 2`
left_sp=`expr \( "$maxcol" - "$length" \) / 2` left_sp=`expr \( "$maxcol" - "$length" \) / 2`
right_sp=`expr "$maxcol" - "$length" - "$left_sp"` right_sp=`expr "$maxcol" - "$length" - "$left_sp"`
header=`printf "%.*s %s %.*s" "$left_sp" "$equal_chars"\ header=`printf "%.*s %s %.*s" "$left_sp" "$equal_chars"\
"$hdr_txt_2" "$right_sp" "$equal_chars"` "$hdr_txt_2" "$right_sp" "$equal_chars"`
# fold using recursive passes ('g' used in fold_it_1 didn't work) # fold using recursive passes ('g' used in fold_it_1 didn't work)
if [ -z "$1" ]; then if [ -z "$1" ]; then
# init recursive env # init recursive env
cp $infile /tmp/wip cp $infile $temp_dir/wip
fi fi
testcol=`expr "$maxcol" + 1` testcol=`expr "$maxcol" + 1`
foldcol=`expr "$maxcol" - 1` # for the inserted '\' char foldcol=`expr "$maxcol" - 1` # for the inserted '\' char
gsed "/.\{$testcol\}/s/\(.\{$foldcol\}\)/\1\\\\\n\\\\/" < /tmp/wip\ gsed "/.\{$testcol\}/s/\(.\{$foldcol\}\)/\1\\\\\n\\\\/" \
>> /tmp/wip2 < $temp_dir/wip >> $temp_dir/wip2
diff /tmp/wip /tmp/wip2 > /dev/null 2>&1
diff $temp_dir/wip $temp_dir/wip2 > /dev/null 2>&1
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
mv /tmp/wip2 /tmp/wip mv $temp_dir/wip2 $temp_dir/wip
fold_it_2 "recursing" fold_it_2 "recursing"
else else
echo "$header" > $outfile echo "$header" > $outfile
echo "" >> $outfile echo "" >> $outfile
cat /tmp/wip2 >> $outfile cat $temp_dir/wip2 >> $outfile
rm /tmp/wip* rm -rf $temp_dir
fi fi
return 0 return 0
} }
fold_it() { fold_it() {
# ensure input file doesn't contain a TAB # ensure input file doesn't contain a TAB
grep $'\t' $infile >> /dev/null 2>&1 grep $'\t' $infile >> /dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo echo
echo "Error: infile contains a TAB character, which is not" echo "Error: infile contains a TAB character, which is not"
skipping to change at page 20, line 21 skipping to change at page 22, line 8
fi fi
fold_it_1 fold_it_1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
fold_it_2 fold_it_2
return $? return $?
fi fi
return 0 return 0
} }
unfold_it_1() { unfold_it_1() {
temp_dir=`mktemp -d`
# output all but the first two lines (the header) to wip file # output all but the first two lines (the header) to wip file
awk "NR>2" $infile > /tmp/wip awk "NR>2" $infile > $temp_dir/wip
# unfold wip file # unfold wip file
gsed ":x; /.*\\\\$/N; s/\\\\\n[ ]*//; tx" /tmp/wip > $outfile gsed ":x; /.*\\\\$/N; s/\\\\\n[ ]*//; tx" $temp_dir/wip > $outfile
# clean up and return # clean up and return
rm /tmp/wip rm -rf $temp_dir
return 0 return 0
} }
unfold_it_2() { unfold_it_2() {
temp_dir=`mktemp -d`
# output all but the first two lines (the header) to wip file # output all but the first two lines (the header) to wip file
awk "NR>2" $infile > /tmp/wip awk "NR>2" $infile > $temp_dir/wip
# unfold wip file # unfold wip file
gsed ":x; /.*\\\\$/N; s/\\\\\n[ ]*\\\\//; tx" /tmp/wip > $outfile gsed ":x; /.*\\\\$/N; s/\\\\\n[ ]*\\\\//; tx" $temp_dir/wip \
> $outfile
# clean up and return # clean up and return
rm /tmp/wip rm -rf $temp_dir
return 0 return 0
} }
unfold_it() { unfold_it() {
# check if file needs unfolding # check if file needs unfolding
line=`head -n 1 $infile` line=`head -n 1 $infile`
result=`echo $line | fgrep "$hdr_txt_1"` result=`echo $line | fgrep "$hdr_txt_1"`
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
unfold_it_1 unfold_it_1
return $? return $?
skipping to change at page 23, line 4 skipping to change at page 24, line 43
fi fi
} }
main() { main() {
if [ "$#" == "0" ]; then if [ "$#" == "0" ]; then
print_usage print_usage
exit 1 exit 1
fi fi
process_input $@ process_input $@
if [[ $reversed -eq 0 ]]; then if [[ $reversed -eq 0 ]]; then
fold_it fold_it
code=$? code=$?
else else
unfold_it unfold_it
code=$? code=$?
fi fi
exit $code exit $code
} }
main "$@" main "$@"
<CODE ENDS>
Acknowledgements Acknowledgements
The authors thank the following folks for their various contributions The authors thank the following folks for their various contributions
(sorted by first name): Benoit Claise, Gianmarco Bruno, Italo Busi, (sorted by first name): Benoit Claise, Gianmarco Bruno, Italo Busi,
Joel Jaeggli, Jonathan Hansford, Lou Berger, Martin Bjorklund, and Joel Jaeggli, Jonathan Hansford, Lou Berger, Martin Bjorklund, and
Rob Wilton. Rob Wilton.
The authors additionally thank the RFC Editor for confirming that The authors additionally thank the RFC Editor for confirming that
there is no set convention today for handling long lines in artwork/ there is no set convention today for handling long lines in artwork/
sourcecode inclusions. sourcecode inclusions.
 End of changes. 62 change blocks. 
122 lines changed or deleted 172 lines changed or added

This html diff was produced by rfcdiff 1.47. The latest version is available from http://tools.ietf.org/tools/rfcdiff/