NETMOD Working Group K. Watsen Internet-Draft Watsen Networks Intended status: Best Current PracticeQ. Wu Expires: September 11, 2019 Huawei TechnologiesA. Farrel Expires: October 8, 2019 Old Dog ConsultingB. Claise Cisco Systems, Inc. March 10,Q. Wu Huawei Technologies April 6, 2019 Handling Long Lines in Inclusions in Internet-Drafts and RFCsdraft-ietf-netmod-artwork-folding-01draft-ietf-netmod-artwork-folding-02 Abstract This documentintroducesdefines a simple and yet time-proven strategy for handling long lines in inclusions in internet drafts and RFCs using a backslash ('\') character to indicate where line-folding has occurred. The strategy works on any text-based content, but is primarily intended for a structured sequence oflines, such as would be referenced by the <sourcecode> element defined in Section 2.48 of RFC 7991,lines rather than fortwo- dimensional imagery, such as would be referenced by the <artwork> element defined in Section 2.5 of RFC 7991.two-dimensional imagery. The approach produces consistent results, regardless of the content, that is bothself- documentingself-documenting and enables automated reconstitution of the original content. Status of This Memo This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet- Drafts is at https://datatracker.ietf.org/drafts/current/. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." This Internet-Draft will expire onSeptember 11,October 8, 2019. Copyright Notice Copyright (c) 2019 IETF Trust and the persons identified as the document authors. All rights reserved. This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Table of Contents 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 2. Applicability Statement . . . . . . . . . . . . . . . . . . . 3 3. Requirements Language . . . . . . . . . . . . . . . . . . . . 4 4. Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4.1. Automated Folding of Long Lines in Text Content . . . . . 4 4.2. Automated Reconstitution of the Original Text Content . . 4 5. Limitations . . . . . . . . . . . . . . . . . . . . . . . . .45 5.1. Not Recommended for Graphical Artwork . . . . . . . . . . 5 5.2. Doesn't Work as Well as Format-Specific Options . . . . . 5 6.Folded StructureTwo Folding Strategies . . . . . . . . . . . . . . . . . . . 5 6.1. Comparison . . . .5 6.1. Header. . . . . . . . . . . . . . . . . . . 6 6.2. Recommendation . . . . . . .6 6.2. Body. . . . . . . . . . . . . . 6 7. The Single Backslash Strategy ('\') . . . . . . . . . . . . . 67. Algorithm7.1. Folded Structure . . . . . . . . . . . . . . . . . . . . 6 7.1.1. Header . . . . . . . . . . . . . . . . . . . . . . . 67.1. Automated Folding7.1.2. Body . . . . . . . . . . . . . . . . . . . .6 7.1.1. Manual. . . . 7 7.2. Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 7 7.2.1. Folding . . . . . . . . . . . . . . . . . . . . . . . 77.2. Automated7.2.2. Unfolding . . . . . . . . . . . . . . . . . . . . . . 8 8.Examples .The Double Backslash Strategy ('\\') . . . . . . . . . . . . 9 8.1. Folded Structure . . . . . . . . . . . . .8 8.1. Simple Example Showing Boundary Conditions. . . . . . . 98.2. Example Showing Multiple Wraps of a Single Line8.1.1. Header . . . . .9 8.3. Example With Native Backslash. . . . . . . . . . . . . .10 8.4. Example With Native Whitespace. . . . 9 8.1.2. Body . . . . . . . . .10 8.5. Example of Manual Wrapping. . . . . . . . . . . . . . .10 9. Security Considerations9 8.2. Algorithm . . . . . . . . . . . . . . . . . . .13 10. IANA Considerations. . . . . 10 8.2.1. Folding . . . . . . . . . . . . . . . .13 11. References. . . . . . . 10 8.2.2. Unfolding . . . . . . . . . . . . . . . . . .13 11.1. Normative References. . . . 11 9. Examples . . . . . . . . . . . . . .13 11.2. Informative References. . . . . . . . . . . . 12 9.1. Example Showing Boundary Conditions . . . . .13 Appendix A. POSIX Shell Script. . . . . . 12 9.1.1. Using '\' . . . . . . . . . . .15 Acknowledgements. . . . . . . . . . . 12 9.1.2. Using '\\' . . . . . . . . . . . . .19 Authors' Addresses. . . . . . . . 12 9.2. Example Showing Multiple Wraps of a Single Line . . . . . 13 9.2.1. Using '\' . . . . . . . . . .20 1. Introduction [RFC7994] sets out the requirements for plain-text RFCs and states that each line of an RFC. . . . . . . . . . . . 13 9.2.2. Using '\\' . . . . . . . . . . . . . . . . . . . . . 13 9.3. Example Showing Smart Folding . . . . . . . . . . . . . . 13 9.3.1. Using '\' . . . . . . . . . . . . . . . . . . . . . . 13 9.3.2. Using '\\' . . . . . . . . . . . . . . . . . . . . . 14 10. Security Considerations . . . . . . . . . . . . . . . . . . . 15 11. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 16 12. References . . . . . . . . . . . . . . . . . . . . . . . . . 16 12.1. Normative References . . . . . . . . . . . . . . . . . . 16 12.2. Informative References . . . . . . . . . . . . . . . . . 16 Appendix A. POSIX Shell Script . . . . . . . . . . . . . . . . . 17 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 23 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 23 1. Introduction [RFC7994] sets out the requirements for plain-text RFCs and states that each line of an RFC (and hence of anInternet-Draft)Internet-Draft) must be limited to 72 characters followed by the character sequence that denotes an end-of-line (EOL). Internet-Drafts and RFCs often include example text or code fragments. Many times the example text or code exceeds the 72 character line-length limit. The `xml2rfc` utility does not attempt to wrap the content of such inclusions, simply issuing a warning whenever lines exceed 69 characters. According to the RFC Editor, there is currently no convention in place for how to handle long lines in such inclusions, other than advising authors to clearly indicate what manipulation has occurred. This document introduces a simple and yet time-proven strategy for handling long lines using a backslash ('\') character to indicate where line-folding has occurred. The strategy works on any text based inclusion, but is 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]. The approach produces consistent results, regardless of the content, that is both self-documenting and enables automated reconstitution of the original content. 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 is in the Nth column and is immediately followed by an end of line character sequence. 2. Applicability Statement The format and algorithm defined in this document may be used in any context, whether for IETF documents or in other situations where structured folding is desired. Within the IETF, this work primarily targets the xml2rfc v3 <sourcecode> element (Section 2.48 of [RFC7991]) and the xml2rfc v2 <artwork> element (Section 2.5 of [RFC7749]) that, for lack of a better option, is currently used for both source code and artwork. 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 generally not recommended. 3. Requirements Language The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here. 4. Goals 4.1. Automated Folding of Long Lines in Text Content Automated folding of long lines is needed in order to support draft compilations that entail a) validation of source input files (e.g., XML, JSON, ABNF, ASN.1) and/or b) dynamic generation of output, using a tool that doesn't observe line lengths, that is stitched into the final document to be submitted. Generally, in order for tooling to be able to process input files, the files must belimitedin their original/natural state, which may entail them having some long lines. Thus, these source files need to be modified before inclusion in the document in order to satisfy the line length limits. This modification SHOULD be automated to reduce effort and errors resulting from manual processing. Similarly, dynamically generated output (e.g., tree diagrams) must also be modified, if necessary, in order for the resulting document to satisfy the line length limits. When needed, this effort again SHOULD be automated to reduce effort and errors resulting from manual processing. 4.2. Automated Reconstitution of the Original Text Content Automated reconstitution of the original content is needed to support validation of text-based inclusions extracted from documents. YANG [RFC7950] modules are already extracted from Internet-Drafts and validated as part of the draft-submission process. Additionally, there has been some discussion regarding needing to also validate instance examples (i.e., XML/JSON documents) contained within Internet-Drafts ([yang-doctors-thread]). Thus, it SHOULD be possible to mechanically reconstitute the original text content in order to utilize such tooling. 5. Limitations 5.1. Not Recommended for Graphical Artwork While the solution presented in this document will work on any kind of text-based content, it is most useful on content that represents source code (XML, JSON, etc.) or, more generally, on content that has not been laid out in two dimensions (e.g., diagrams). Fundamentally, the issue is whether the text content remains readable once folded. Text content that is unpredictable is especially susceptible to looking bad when folded; falling into this category are most UML diagrams, YANG tree diagrams, and ASCII art in general. It is NOT RECOMMENDED to72 characters followed byuse thecharacter sequencesolution presented in this document on graphical artwork. 5.2. Doesn't Work as Well as Format-Specific Options The solution presented in this document works generically for all text-based content, as it only views content as plain text. However, various formats sometimes have built-in mechanisms thatdenotes an end-of-line (EOL). Internet-Draftsare better suited to prevent long lines. For instance, both the `pyang` andRFCs often include example text or code fragments.`yanglint` utilities have the command line option "--tree-line-length" that can be used to indicate a desired maximum line length for when generating tree diagrams [RFC8340]. Inorderanother example, some source formats (e.g., YANG [RFC7950]) allow any quoted string torender the formattingbe broken up into substrings separated by a concatenation character (e.g., '+'), any of which can be on a different line. In yet another example, some languages allow factoring blocks of code into call outs, suchtext itas functions. Using such call outs isusually presentedespecially 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 selected format to avoid long lines. 6. Two Folding Strategies This document defines two nearly identical strategies for folding text-based content. The Single Backslash Strategy ('\'): Uses afigure usingbackslash ('\') character at the"<sourcecode>" element inend of thesource XML. Many timesline where folding occurs, and assumes that theexample text or code exceedscontinuation begins at the72first non- whitespace characterline-length limit andon the`xml2rfc` utility does not attempt to wrapfollowing line. The Double Backslash Strategy ('\\'): Uses a backslash ('\') character at thecontentend ofsuch inclusions, simply issuingthe line where folding occurs, and assumes that the continuation begins after awarning whenever lines exceed 69 characters. According tosecond backslash ('\') character on theRFC Editor,following line. 6.1. Comparison The first strategy produces more readable output, however it is significantly more likely to encounter unfoldable input (e.g., there iscurrently no conventionexists a line anywhere inplace for how to handle long lines, other than advising authors to clearly indicate what manipulation has occurred. This document introducesthe input ending with asimplebackslash character, or there exists a long line containing only space andyet time-proven strategybackslash characters) and, forhandlinglong linesin inclusions in drafts using a backslash ('\') character where line-folding has occurred.that can be folded, automation implementations are likely to encounter scenarios that will produce errors without special care. The second strategyworks on any text based inclusion,produces less readable output, but isprimarily intendedunlikely to encounter unfoldable input, there are no long lines that cannot be folded, and no special care is required for when folding astructured sequence of lines, such as would be referenced by the <sourcecode> element defined in Section 2.48 of [RFC7991], rather thanlong line. 6.2. Recommendation It is RECOMMENDED fortwo- dimensional imagery, such as would be referenced byimplementations to first attempt to fold content using the<artwork> element definedsingle backslash strategy and, only inSection 2.5 of [RFC7991]. The approach produces consistent results, regardless ofthecontent,unlikely event that it cannot fold the input or the folding logic isboth self- documenting and enables automated reconstitution ofunable to cope with a contingency occurring on theoriginal content. Notedesired folding column, then fallback to the double backslash strategy. 7. The Single Backslash Strategy ('\') 7.1. Folded Structure Text content thattext files are representhas been folded as specified by this strategy MUST adhere to the following structure. 7.1.1. Header The header is two lineshaving theirlong. The firstcharacter in column 1, and alinelength of N where the last characterisintheNth column and is immediately followedfollowing 45-character string that MAY be surrounded byan endany number of printable characters. This first linecharacter sequence. 2. Applicability Statement The formatcannot itself be folded. NOTE: '\' line wrapping per BCP XX (RFC XXXX) [Note to RFC Editor: Please replace XX andalgorithm defined inXXXX with the numbers assigned to this documentmay be usedand delete this note. Please make this change inany context, whether for IETF documents ormultiple places inother situations where structured folding is desired. Within the IETF,thisworkdocument.] The second line isprimarily targeted to xml2rfc v3 <sourcecode> element (Section 2.48 of [RFC7991]) and xml2rfc v2 <artwork> element (Section 2.5 of [RFC7749]) that, for lack ofabetter option, is currently used for both source code and artwork.blank line. Thiswork may be also be usedline provides visual separation for readability. 7.1.2. Body The character encoding is thexml2rfc v3 <artwork> element (Section 2.5 of [RFC7991]) but,same as described in Section5.1, it is generally not recommended. 3. Requirements Language The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here. 4. Goals 4.1. Automated Folding2 ofLong[RFC7994], except that, per [RFC7991], tab characters are prohibited. Lines that have a backslash ('\') occurring as the last character inText Content Automateda line are considered "folded". Really long lines may be folded multiple times. 7.2. Algorithm This section describes the process for foldingofand unfolding long linesis neededwhen they are encountered inorder to support draft compilations that entail a) validationa single instance ofsourcetext 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 Folding is assumed to be automated although authors may perform the folding steps manually. Determine the desired maximum line length from inputfiles (e.g., XML, JSON, ABNF, ASN.1) and/or b) dynamic generation of output, usingto the automated line-wrapping process, such as from atool that doesn't observecommand linelengths,parameter. If no value is explicitly specified, the value "69" SHOULD be used. Ensure that the desired maximum line length isstitched intonot less than thefinal document tominimum header, which is 46 characters. If the desired maximum line length is less than this minimum, exit (this text-based content cannot besubmitted. Generally, in orderfolded). Scan the text content fortooling to be ablehorizontal tab characters. If any horizontal tab characters appear, either resolve them toprocessspace characters or exit, forcing the inputfiles,provider to convert them to space characters themselves first. Scan thefiles must be in their original/natural state, which may include having some long lines. Thus, these source filestext content to see if any line exceeds the desired maximum. If no line exceeds the desired maximum, exit (this text content does not need to bemodified before inclusion infolded). Scan thedocument in ordertext content tosatisfy theensure no existing lines already end with a backslash ('\') character, as this would lead to an ambiguous result. If such a linelength limits. This modification SHOULDis found, exit (this text content cannot beautomatedfolded). If this text content needs toreduce effortanderrors resulting from manual effort. Similarly, dynamically generated output (e.g., tree diagrams) must alsocan bemodified, if necessary,folded, insert the header described inorder forSection 7.1.1, ensuring that any additional printable characters surrounding theresulting document to satisfyheader does not result in a line exceeding the desired maximum.. For each linelength limits. When needed, this effort again SHOULD be automated to reduce effort and errors resultingin the text content, frommanual effort. 4.2. Automated Reconstitution oftop-to-bottom, if theOriginal Text Content Automated reconstitution ofline exceeds theoriginal content is needed to support validation of artwork extracted from documents. YANG [RFC7950] modules are already extracted from Internet-Drafts and validated as part ofdesired maximum, then fold thedraft-submission process. Additionally, there has been some discussion regarding needing to doline by: 1. Determine where thesame for instance examples (i.e., XML/JSON documents) contained within Internet-Drafts ([yang-doctors-thread]). Thus, it SHOULDfold will occur. This location MUST bepossible to mechanically reconstitutebefore or at theoriginal text content in orderdesired maximum column, and MUST NOT precede a space (' ') character. 2. At the location where the fold is tosatisfy tooling input parsers. 5. Limitations 5.1. Not Recommended for Graphical Artwork Whileoccur, insert a backslash ('\') character followed by thesolution presented in this document will work onend of line character sequence. 3. On the following line, insert anykindnumber oftext-based content, itspace (' ') characters. The result of the previous operation ismost useful on contentthatrepresents source code (XML, JSON, etc.) or, more generally, on contentthe next line starts with an arbitrary number of space (' ') characters, followed by the character thathas not been laid outwas previously occupying the position where the fold occurred. Continue intwo dimensions (e.g., diagrams). Fundamentally,this manner until reaching theissue is whetherend of the textcontent remains readable once folded. Text contentcontent. Note that this algorithm naturally addresses the case where the remainder of a folded line isunpredictable is especially susceptiblestill longer than the desired maximum, and hence needs tolooking bad when folded; falling intobe folded again, ad infinitum. The process described in thiscategory are most UML diagrams, YANG tree diagrams, and ASCII artsection is illustrated by the "fold_it_1()" function ingeneral. ItAppendix A. 7.2.2. Unfolding All unfolding isNOT RECOMMENDEDassumed tousebe automated, although a reader will mentally perform thesolution presentedact 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 inthis documentSection 7.1.1. If the header is not present, starting ongraphical artwork. 5.2. Doesn't Work as Well as Format-Specific Options The solution presented in this document works generically for all text-basedthe first line of the text content,as it only views content as plain text. However, various formats sometimes have built-in mechanisms that are better suitedexit (this text contents does not need toprevent long lines.be unfolded). Remove the 2-line header from the text content. Forinstance, botheach line in the`pyang` and `yanglint` utilities havetext content, from top-to-bottom, if thecommandlineoption "--tree-line-length" that can be used to indicatehas adesired maximumbackslash ('\') character immediately followed by the end of linelength for when generating tree diagrams [RFC8340]. In another example, some source formats (e.g., YANG [RFC7950]) allow any quoted string tocharacter sequence, then the line can bebroken up into substrings separated by a concatenationunfolded. Remove the backslash ('\') character, the end of line character(e.g., '+'),sequence, and anyofleading space (' ') characters, whichcan be on a differentwill bring up the next 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 whenThen continue to scan each line insome deeply-nested code, as they typically resettheindentation back totext content starting with thefirst column. Itcurrent line (in case it was multiply folded). Continue in this manner until reaching the end of the text content. The process described in this section isRECOMMENDED that authors do as much as possible withinillustrated by theselected format to avoid long lines. 6."unfold_it_1()" function in Appendix A. 8. The Double Backslash Strategy ('\\') 8.1. Folded Structure Text content that has been folded as specified by thisdocumentstrategy MUSTcontainadhere to the following structure.6.1.8.1.1. Header The header is two lines long. The first line is the following 46-character string that MAY be surrounded by any number of printable characters. This first line cannot itself be folded. NOTE: '\\' line wrapping per BCP XX (RFC XXXX) [Note to RFC Editor: Please replace XX and XXXX with the numbers assigned to this document and delete this note. Please make this change in multiple places in this document.] The second line is a blank line. This line provides visual separation for readability.6.2.8.1.2. Body The character encoding is the same as described in Section 2 of [RFC7994], except that, per [RFC7991], tab characters are prohibited. Lines that have a backslash ('\') occurring as the last character in a line immediately followed by the end of line character sequence, when the subsequent line starts with a backslash ('\') as the first non-space (' ') character, are considered "folded". Really long lines may be folded multiple times.7.8.2. Algorithm This section describes theprocessesprocess for folding and unfolding long lines when they are encountered in a single instance of 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] doesjustthis.7.1. Automated8.2.1. Folding Folding is assumed to be automated, although authors may perform the folding steps manually. Determine the desired maximum line length from input to the automated 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 minimum header, which is4645 characters. If the desired maximum line length is less than this minimum, exit (this text-based content cannot be folded). Scan the text content for horizontal tab characters. If any horizontal tab characters appear, either resolve them to space characters or exit, forcing the input provider to convert them to space characters themselves first. 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 not need to be folded). Scan the text content to ensure no existing lines already end with a backslash ('\') characterwhenwhile the subsequent line starts with a backslash ('\') character as the first non-space (' ') character, as this would lead to an ambiguous result. 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 headerasdescribed in Section6.1.8.1.1, ensuring that any additional printable characters surrounding the header does not result in a line exceeding the desired maximum.. For each line in the text content, from top-to-bottom, if the line exceeds the desired maximum, then fold the line by: 1. Determine where the fold will occur. This location MUST be before or at the desired maximumcolumn by 1) insertingcolumn. 2. At thecharacterlocation where the fold is to occur, insert a first backslash ('\') characterat the maximum column, 2) insertingfollowed by the end of line charactersequence, insertingsequence. 3. On the following line, insert any number of space (' ')characters, and 4) insertingcharacters followed by afurthersecond backslash ('\') character. The result ofthisthe previous operation is that the next line starts with an arbitrary number of space (' ') characters, followed by a backslash ('\') character, immediately followed by the character that was previouslyinoccupying themaximum column.position where the fold occurred. Continue in this manner until reaching the end of the text content. Note that this algorithm naturally addresses the case where the remainder of a folded line is still longer than the desired maximum, and hence needs to be folded again, ad infinitum. The process described in this section is illustrated by the"fold_it()""fold_it_2()" function in Appendix A.7.1.1. Manual Folding Authors may choose to fold text examples and source code by hand to produce a text content that is more pleasant for a human reader but which can still be automatically unfolded (as described in Section 7.2) to produce single lines that are longer than the maximum document line length. For example, an author may choose to make the fold at convenient gaps between words such that the backslash is placed in a lower column number than the text content's maximum column value. Additionally, an author may choose to indent the start of a continuation line by inserting space characters before the line continuation marker backslash character. Manual folding may also help handle the cases that cannot be automatically folded as described in Section 7. Authors MUST produce a result that adheres to the structure described in Section 6. 7.2. Automated8.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 Section6.1.8.1.1. If the header is not present, starting on the first line of the text content, exit (thisartworktext content does not need to be unfolded). Remove the 2-line header from the text content. For each line in the text content, from top-to-bottom, if the line has a backslash ('\') character immediately followed by the end of line character sequence, and if the next line has a backslash ('\') character as the first non-space (' ') character, then the lines can be unfolded. Remove the first backslash ('\') character, the end of line character sequence, any leading space (' ') characters, and the second backslash ('\') character, which will bring up the next line. Then continue to scan each line in the text content starting with the current line (in case it was multiply folded). Continue in this manner until reaching the end of the text content. The process described in this section is illustrated by the"unfold_it()""unfold_it_2()" function in Appendix A.8.9. Examples The following self-documenting examples illustrate folded text-based content. The source text content cannot be presented here, as it would againneed tobe folded. Alas, only theresultresults can be provided.The examples in Sections 8.1 through 8.4 were automatically folded on column 69, the default value. Section 8.5 shows an example of manual folding. 8.1. Simple9.1. Example Showing Boundary Conditions This example illustratesaboundarycondition test using numbers for counting purposes.condition. The input contains5seven lines, each line one character longer than theprevious. Any printable character (including ' ' and '\') can be used as a substitute for any number, exceptprevious line. Numbers foron the 4th row, the trailing '9'counting purposes. The default desired maximum column value "69" isnot allowed to be aused. 9.1.1. Using '\'character if the first non-space character of the next line is a=========== NOTE: '\'character, as that would lead to an ambiguous result.line wrapping per BCP XX (RFC XXXX) =========== 123456789012345678901234567890123456789012345678901234567890123456 1234567890123456789012345678901234567890123456789012345678901234567 12345678901234567890123456789012345678901234567890123456789012345678 123456789012345678901234567890123456789012345678901234567890123456789 12345678901234567890123456789012345678901234567890123456789012345678\ 90 12345678901234567890123456789012345678901234567890123456789012345678\ 901 12345678901234567890123456789012345678901234567890123456789012345678\ 9012 9.1.2. Using '\\' ========== NOTE: '\\' line wrapping per BCP XX (RFC XXXX) =========== 123456789012345678901234567890123456789012345678901234567890123456 1234567890123456789012345678901234567890123456789012345678901234567 12345678901234567890123456789012345678901234567890123456789012345678 123456789012345678901234567890123456789012345678901234567890123456789 12345678901234567890123456789012345678901234567890123456789012345678\ \90 12345678901234567890123456789012345678901234567890123456789012345678\ \901 12345678901234567890123456789012345678901234567890123456789012345678\ \90128.2.9.2. Example Showing Multiple Wraps of a Single Line This example illustratesonewhat happens when very long line(280 characters). Any printable character (including ' ' and '\') canneeds to beused as a substitutefolded multiple times. The input contains one line containing 280 characters. Numbers forany number. ==========counting purposes. The default desired maximum column value "69" is used. 9.2.1. Using '\' =========== NOTE:'\\''\' line wrapping per BCP XX (RFC XXXX) =========== 12345678901234567890123456789012345678901234567890123456789012345678\\9012345678901234567890123456789012345678901234567890123456789012345\ \6789012345678901234567890123456789012345678901234567890123456789012\ \3456789012345678901234567890123456789012345678901234567890123456789\ \01234567890 8.3. Example With Native Backslash This example has a '\' character in the wrapping column. The native text includes the sequence "fish\fowl" with the '\' character occurring on the 69th column. string1="The quick brown dog jumps over the lazy dog which is a fish\ \\fowl as appropriate" 8.4. Example With Native Whitespace This example has whitespace spanning the wrapping column. The native input contains 15 space (' ') characters between "like" and "white".90123456789012345678901234567890123456789012345678901234567890123456\ 78901234567890123456789012345678901234567890123456789012345678901234\ 56789012345678901234567890123456789012345678901234567890123456789012\ 34567890 9.2.2. Using '\\' ========== NOTE: '\\' line wrapping per BCP XX (RFC XXXX) ===========Sometimes our strings include multiple spaces such as "We like \ \ white space." 8.5.12345678901234567890123456789012345678901234567890123456789012345678\ \9012345678901234567890123456789012345678901234567890123456789012345\ \6789012345678901234567890123456789012345678901234567890123456789012\ \3456789012345678901234567890123456789012345678901234567890123456789\ \01234567890 9.3. Exampleof Manual WrappingShowing Smart Folding This example illustrates how readability can be improved via "smart" folding, whereby folding occurs at format-specific locations and format-specific indentations are used. The text content was manuallywrapped to causefolded, since thefolding to occur after each term, putting each term on its own line. Indentation is used to additionally improve readability. Also notescript in the appendix does not implement smart folding. Note that themandatoryheader is surrounded by different printable charactersthanthen shown in theotherscript-generated examples.=====9.3.1. Using '\' [NOTE: '\' line wrapping per BCP XX (RFC XXXX)] <yang-library xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library" xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores"> <module-set> <name>config-modules</name> <module> <name>ietf-interfaces</name> <revision>2018-02-20</revision> <namespace>\ urn:ietf:params:xml:ns:yang:ietf-interfaces\ </namespace> </module> ... </module-set> ... </yang-library> Below is the equivalent to the above, but it was folded using the script in the appendix. =========== NOTE:'\\''\' line wrapping per BCP XX (RFC XXXX)================ <yang-library xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library" xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores"> <module-set> <name>config-modules</name> <module> <name>ietf-interfaces</name> <revision>2018-02-20</revision><namespace>\ \urn:ietf:params:xml:ns:yang:ietf-interfaces\ \</namespace><namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namesp\ ace> </module> ... </module-set> ... </yang-library> 9.3.2. Using '\\' [NOTE: '\\' line wrapping per BCP XX (RFC XXXX)] <yang-library xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library" xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores"> <module-set> <name>config-modules</name> <module><name>ietf-ip</name> <revision>2018-02-22</revision><name>ietf-interfaces</name> <revision>2018-02-20</revision> <namespace>\\urn:ietf:params:xml:ns:yang:ietf-ip\\urn:ietf:params:xml:ns:yang:ietf-interfaces\ \</namespace> </module><import-only-module> <name>ietf-yang-types</name> <revision>2013-07-15</revision> <namespace>\ \urn:ietf:params:xml:ns:yang:ietf-yang-types\ \</namespace> </import-only-module> <import-only-module> <name>ietf-inet-types</name> <revision>2013-07-15</revision> <namespace>\ \urn:ietf:params:xml:ns:yang:ietf-inet-types\ \</namespace> </import-only-module>... </module-set><schema> <name>config-schema</name> <module-set>config-modules</module-set> </schema> <schema> <name>state-schema</name> <module-set>config-modules</module-set> <module-set>state-modules</module-set> </schema> <datastore> <name>ds:startup</name> <schema>config-schema</schema> </datastore> <datastore> <name>ds:running</name> <schema>config-schema</schema> </datastore> <datastore> <name>ds:operational</name> <schema>state-schema</schema> </datastore> <content-id>75a43df9bd56b92aacc156a2958fbe12312fb285</content-id>... </yang-library>The manual folding produces a more readable result thanBelow is thefollowingequivalentfolding that contains no indentation.to the above, but it was folded using the script in the appendix. ========== NOTE: '\\' line wrapping per BCP XX (RFC XXXX) =========== <yang-library xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library" xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores"> <module-set> <name>config-modules</name> <module> <name>ietf-interfaces</name> <revision>2018-02-20</revision> <namespace>urn:ietf:params:xml:ns:yang:ietf-interfaces</namesp\ \ace> </module><module> <name>ietf-ip</name> <revision>2018-02-22</revision> <namespace>urn:ietf:params:xml:ns:yang:ietf-ip</namespace> </module> <import-only-module> <name>ietf-yang-types</name> <revision>2013-07-15</revision> <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namesp\ \ace> </import-only-module> <import-only-module> <name>ietf-inet-types</name> <revision>2013-07-15</revision> <namespace>urn:ietf:params:xml:ns:yang:ietf-inet-types</namesp\ \ace> </import-only-module>... </module-set><schema> <name>config-schema</name> <module-set>config-modules</module-set> </schema> <schema> <name>state-schema</name> <module-set>config-modules</module-set> <module-set>state-modules</module-set> </schema> <datastore> <name>ds:startup</name> <schema>config-schema</schema> </datastore> <datastore> <name>ds:running</name> <schema>config-schema</schema> </datastore> <datastore> <name>ds:operational</name> <schema>state-schema</schema> </datastore> <content-id>75a43df9bd56b92aacc156a2958fbe12312fb285</content-id>... </yang-library>9.10. Security Considerations This BCP has no Security Considerations.10.11. IANA Considerations This BCP has no IANA Considerations.11.12. References11.1.12.1. Normative References [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, <https://www.rfc-editor.org/info/rfc2119>. [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, May 2017, <https://www.rfc-editor.org/info/rfc8174>.11.2.12.2. Informative References [RFC7749] Reschke, J., "The "xml2rfc" Version 2 Vocabulary", RFC 7749, DOI 10.17487/RFC7749, February 2016, <https://www.rfc-editor.org/info/rfc7749>. [RFC7950] Bjorklund, M., Ed., "The YANG 1.1 Data Modeling Language", RFC 7950, DOI 10.17487/RFC7950, August 2016, <https://www.rfc-editor.org/info/rfc7950>. [RFC7991] Hoffman, P., "The "xml2rfc" Version 3 Vocabulary", RFC 7991, DOI 10.17487/RFC7991, December 2016, <https://www.rfc-editor.org/info/rfc7991>. [RFC7994] Flanagan, H., "Requirements for Plain-Text RFCs", RFC 7994, DOI 10.17487/RFC7994, December 2016, <https://www.rfc-editor.org/info/rfc7994>. [RFC8340] Bjorklund, M. and L. Berger, Ed., "YANG Tree Diagrams", BCP 215, RFC 8340, DOI 10.17487/RFC8340, March 2018, <https://www.rfc-editor.org/info/rfc8340>. [xiax] "The `xiax` Python Package", <https://pypi.org/project/xiax/>. [yang-doctors-thread] "[yang-doctors] automating yang doctor reviews", <https://mailarchive.ietf.org/arch/msg/yang-doctors/ DCfBqgfZPAD7afzeDFlQ1Xm2X3g>. Appendix A. POSIX Shell Script This non-normative appendix section includes a shell script that can both fold and unfold text content. Note that this script is applied only to single text content instances. #!/bin/bash --posix # must be `bash` (not `sh`) print_usage() { echo echo "Folds the text file, only if needed, at the specified" echo "column, according to BCP XX." echo echo "Usage: $0 [-s <strategy>] [-c <col>] [-r] -i<infile><infile>" echo " -o <outfile>" echo echo " -s: strategy to use, '1' or '2' (default: try 1, else 2)" echo " -c: column to fold on (default: 69)" echo " -r: reverses the operation" echo " -i: the input filename" echo " -o: the output filename" echo " -d: show debug messages" echo " -h: show this message" echo echo "Exit status code: zero on success, non-zero otherwise." echo } # global vars, do not edit strategy=0 # auto debug=0 reversed=0 infile="" outfile="" maxcol=69 # default, may be overridden by paramhdr_txt="NOTE:hdr_txt_1="NOTE: '\\' line wrapping per BCP XX (RFC XXXX)" hdr_txt_2="NOTE: '\\\\' line wrapping per BCP XX (RFC XXXX)" equal_chars="==============================================" space_chars=" "fold_it()fold_it_1() { #since upcomming tests are >= (not >) testcol=`expr "$maxcol" + 1` # check ifensure input fileneeds folding grep ".\{$testcol\}"doesn't contain the fold-sequence already pcregrep -M "\\\\\n" $infile >> /dev/null 2>&1 if [ $?-ne-eq 0 ]; thenif [[ $debug -eq 1 ]]; thenecho"nothing to do" fi cpecho "Error1: infile $infile$outfilehas a line ending with a '\\'" echo "character. This file cannot be folded." echo return-11 fi # stash some vars testcol=`expr "$maxcol" + 1` foldcol=`expr "$maxcol" - 1` # for the inserted '\' char # ensure input file doesn't containa TABwhitespace on the fold column grep$'\t'"^.\{$foldcol\} " $infile >> /dev/null 2>&1 if [ $? -eq 0 ]; then echo echo "Error: infilecontainshas aTAB character, which is not"space character occuring after the" echo"allowed.""folding column. This file cannot be folded." echo return 1 fi # center header text length=`expr ${#hdr_txt_1} + 2` left_sp=`expr \( "$maxcol" - "$length" \) / 2` right_sp=`expr "$maxcol" - "$length" - "$left_sp"` header=`printf "%.*s %s %.*s" "$left_sp" "$equal_chars"\ "$hdr_txt_1" "$right_sp" "$equal_chars"` # generate outfile echo "$header" > $outfile echo "" >> $outfile gsed "/.\{$testcol\}/s/\(.\{$foldcol\}\)/\1\\\\\n/g"\ < $infile >> $outfile return 0 } fold_it_2() { # ensure input file doesn't contain the fold-sequence already pcregrep -M "\\\\\n[\ ]*\\\\" $infile >> /dev/null 2>&1 if [ $? -eq 0 ]; then echo echo"Error:"Error2: infile has a line ending with a'\''\\' character" echo" followed"followed by a'\''\\' character as the first non-space" echo" character"character on the next line. This file cannotbe" echo "be folded." echo return 1 fi # center header text length=`expr${#hdr_txt}${#hdr_txt_2} + 2` left_sp=`expr \( "$maxcol" - "$length" \) / 2` right_sp=`expr "$maxcol" - "$length" - "$left_sp"` header=`printf "%.*s %s %.*s" "$left_sp" "$equal_chars"\"$hdr_txt""$hdr_txt_2" "$right_sp" "$equal_chars"` # fold using recursive passes ('g' used in fold_it_1 didn't work) if [ -z "$1" ]; then # init recursive env cp $infile /tmp/wip fi testcol=`expr "$maxcol" + 1` foldcol=`expr "$maxcol" - 1` # for the inserted '\' char gsed "/.\{$testcol\}/s/\(.\{$foldcol\}\)/\1\\\\\n\\\\/" < /tmp/wip\ >>/tmp/wip2 diff /tmp/wip /tmp/wip2 > /dev/null 2>&1 if [ $? -eq 1 ]; then mv /tmp/wip2 /tmp/wip fold_it "recursing" else echo "$header" > $outfile echo "" >> $outfile cat /tmp/wip2 >> $outfile rm /tmp/wip* fi ## following two lines represent a non-functional variant to the ## recursive logic presented in the block above. It used to work ## before the '\' on the next line was added to the format (i.e., ## the trailing '\\\\' in the substitution below), but now there ## is an off-by-one error. Leaving here in case anyone can fix it. #echo/tmp/wip2 diff /tmp/wip /tmp/wip2 > /dev/null 2>&1 if [ $? -eq 1 ]; then mv /tmp/wip2 /tmp/wip fold_it_2 "recursing" else echo "$header" > $outfile#echoecho "" >> $outfile#gsed "/.\{$testcol\}/s/\(.\{$foldcol\}\)/\1\\\\\n\\\\/g"\ < $infilecat /tmp/wip2 >> $outfile rm /tmp/wip* fi return 0 }unfold_it()fold_it() { # ensure input file doesn't contain a TAB grep $'\t' $infile >> /dev/null 2>&1 if [ $? -eq 0 ]; then echo echo "Error: infile contains a TAB character, which is not" echo "allowed." echo return 1 fi # check if file needsunfolding line=`head -n 1folding testcol=`expr "$maxcol" + 1` grep ".\{$testcol\}" $infile| fgrep "$hdr_txt"`>> /dev/null 2>&1 if [ $? -ne 0 ]; then if [[ $debug -eq 1 ]]; then echo "nothing to do" fi cp $infile $outfile return -1 fi if [[ $strategy -eq 1 ]]; then fold_it_1 return $? fi if [[ $strategy -eq 2 ]]; then fold_it_2 return $? fi fold_it_1 if [ $? -ne 0 ]; then fold_it_2 return $? fi return 0 } unfold_it_1() { # output all but the first two lines (the header) to wip(workfile awk "NR>2" $infile > /tmp/wip #in progress)unfold wip file gsed ":x; /.*\\\\$/N; s/\\\\\n[ ]*//; tx" /tmp/wip > $outfile # clean up and return rm /tmp/wip return 0 } unfold_it_2() { # output all but the first two lines (the header) to wip file awk "NR>2" $infile > /tmp/wip # unfold wip file gsed ":x;/.*\\\\\$/N;/.*\\\\$/N; s/\\\\\n[ ]*\\\\//;tx; s/\t//g" /tmp/wip\tx" /tmp/wip > $outfile # clean up and return rm /tmp/wip return 0 } unfold_it() { # check if file needs unfolding line=`head -n 1 $infile` result=`echo $line | fgrep "$hdr_txt_1"` if [ $? -eq 0 ]; then unfold_it_1 return $? fi result=`echo $line | fgrep "$hdr_txt_2"` if [ $? -eq 0 ]; then unfold_it_2 return $? fi if [[ $debug -eq 1 ]]; then echo "nothing to do" fi cp $infile $outfile return -1 } process_input() { while [ "$1" != "" ]; do if [ "$1" == "-h" -o "$1" == "--help" ]; then print_usage exit 1 fi if [ "$1" == "-d" ]; then debug=1 fi if [ "$1" == "-s" ]; then strategy="$2" shift fi if [ "$1" == "-c" ]; then maxcol="$2" shift fi if [ "$1" == "-r" ]; then reversed=1 fi if [ "$1" == "-i" ]; then infile="$2" shift fi if [ "$1" == "-o" ]; then outfile="$2" shift fi shift done if [ -z "$infile" ]; then echo echo "Error: infile parameter missing (use -h for help)" echo exit 1 fi if [ -z "$outfile" ]; then echo echo "Error: outfile parameter missing (use -h for help)" echo exit 1 fi if [ ! -f "$infile" ]; then echo echo "Error: specified file \"$infile\" is does not exist." echo exit 1 fi if [[ $strategy -eq 2 ]]; then min_supported=`expr${#hdr_txt}${#hdr_txt_2} + 8` else min_supported=`expr ${#hdr_txt_1} + 8` fi if [ $maxcol -lt $min_supported ]; then echo echo "Error: the folding column cannot be less than" echo"$min_supported""$min_supported." echo exit 1 fi # this is only because the code otherwise runs out of equal_chars max_supported=`expr ${#equal_chars} + 1 +${#hdr_txt}${#hdr_txt_1} + 1\ + ${#equal_chars}` if [ $maxcol -gt $max_supported ]; then echo echo "Error: the folding column cannot be more than" echo"$max_supported""$max_supported." echo exit 1 fi } main() { if [ "$#" == "0" ]; then print_usage exit 1 fi process_input $@ if [[ $reversed -eq 0 ]]; then fold_it code=$? else unfold_it code=$? fi exit $code } main "$@" Acknowledgements The authors thank the following folks for their various contributions (sorted by first name): Benoit Claise, Gianmarco Bruno, Italo Busi,Jonathan Hansford,Joel Jaeggli, Jonathan Hansford, Lou Berger, Martin Bjorklund,Italo Busi,and Rob Wilton. The authors additionally thank the RFC Editor for confirming that there is no set convention today for handling long lines in artwork/ sourcecode inclusions. Authors' Addresses Kent Watsen Watsen Networks EMail: kent+ietf@watsen.netQin Wu Huawei Technologies EMail: bill.wu@huawei.comAdrian Farrel Old Dog Consulting EMail: adrian@olddog.co.ukBenoit Claise Cisco Systems, Inc.Qin Wu Huawei Technologies EMail:bclaise@cisco.combill.wu@huawei.com