|
24 | 24 | LINKS_RE = re.compile("(?:xref|link):([\./\w_-]*/?[\w_.-]*\.(?:html|adoc))?(#[\w_-]*)?(\[.*?\])", re.M | re.DOTALL)
|
25 | 25 | EXTERNAL_LINK_RE = re.compile("[\./]*([\w_-]+)/[\w_/-]*?([\w_.-]*\.(?:html|adoc))", re.DOTALL)
|
26 | 26 | INCLUDE_RE = re.compile("include::(.*?)\[(.*?)\]", re.M)
|
27 |
| -IFDEF_RE = re.compile(r"^ifdef::(.*?)\[\]", re.M) |
| 27 | +IFDEF_RE = re.compile(r"^if(n?)def::(.*?)\[\]", re.M) |
28 | 28 | ENDIF_RE = re.compile(r"^endif::(.*?)\[\]\r?\n", re.M)
|
29 | 29 | COMMENT_CONTENT_RE = re.compile(r"^^////$.*?^////$", re.M | re.DOTALL)
|
30 | 30 | TAG_CONTENT_RE = re.compile(r"//\s+tag::(.*?)\[\].*?// end::(.*?)\[\]", re.M | re.DOTALL)
|
@@ -410,7 +410,7 @@ def copy_file(info, book_src_dir, src_file, dest_dir, dest_file, include_check=T
|
410 | 410 |
|
411 | 411 | # Check for any includes
|
412 | 412 | if include_check:
|
413 |
| - cleaned_content = remove_conditional_content(content, info, tag=tag) |
| 413 | + cleaned_content = remove_conditional_content(content, info) |
414 | 414 | include_iter = INCLUDE_RE.finditer(cleaned_content)
|
415 | 415 | for include in include_iter:
|
416 | 416 | include_text = include.group(0)
|
@@ -628,12 +628,20 @@ def remove_conditional_content(content, info, tag=None):
|
628 | 628 | # Remove any ifdef content
|
629 | 629 | ifdef = IFDEF_RE.search(content)
|
630 | 630 | while ifdef is not None:
|
631 |
| - ifdef_distros = ifdef.group(1).split(",") |
| 631 | + is_not_def = ifdef.group(1) == "n" |
| 632 | + ifdef_distros = ifdef.group(2).split(",") |
632 | 633 | pos = ifdef.start()
|
633 | 634 | end = ifdef.end()
|
634 | 635 |
|
635 |
| - # Distro isn't in the ifdef content, so remove it |
636 |
| - if info['distro'] not in ifdef_distros: |
| 636 | + # Determine if we should strip the conditional content, based on the distro |
| 637 | + strip_content = False |
| 638 | + if is_not_def and info['distro'] in ifdef_distros: |
| 639 | + strip_content = True |
| 640 | + elif not is_not_def and info['distro'] not in ifdef_distros: |
| 641 | + strip_content = True |
| 642 | + |
| 643 | + # Remove the conditional content |
| 644 | + if strip_content: |
637 | 645 | # Find the correct endif for the current ifdef
|
638 | 646 | search_pos = end
|
639 | 647 | endpos = len(content)
|
|
0 commit comments