extract *TX* tag or otherwise the *common_properties* from a xml comment

    Paremeters
    ----------
    comment : str
        xml string comment

    Returns
    -------
    comment : str
        extracted string
195069
def extract_cncomment_xml(comment):
    

    comment = comment.replace(' xmlns="http://www.asam.net/mdf/v4"', "")
    try:
        comment = ET.fromstring(comment)
        match = comment.find(".//TX")
        if match is None:
            common_properties = comment.find(".//common_properties")
            if common_properties is not None:
                comment = []
                for e in common_properties:
                    field = f'{e.get("name")}: {e.text}'
                    comment.append(field)
                comment = "\n".join(field)
            else:
                comment = ""
        else:
            comment = match.text or ""
    except ET.ParseError:
        pass

    return comment
179930
def to_xml_string(str = "")
      author = @comments.authors[author_index]
      str << ('<comment ref="' << ref << '" authorId="' << author_index.to_s << '">')
      str << '<text>'
      unless author.to_s == ""
        str << '<r><rPr><b/><color indexed="81"/></rPr>'
        str << ("<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>")
      end
      str << '<r>'
      str << '<rPr><color indexed="81"/></rPr>'
      str << ('<t>' << ::CGI.escapeHTML(text) << '</t></r></text>')
      str << '</comment>'
    end
1111744
def comment_parser(comment):
    
    try:
        if comment['type'] != 'comment':
            return item_parser(comment)
    except KeyError:
        return deleted_parser(comment)
    return Comment(
        comment['id'],
        comment['by'],
        __check_key('kids', comment),  # some comments do not have kids key
        comment['parent'],
        comment['text'],
        comment['time'],
        comment['type'],
    )
622744
def _get_remarks_component(self, string, initial_pos):
    '''  '''
    remarks_code = string[initial_pos:initial_pos + self.ADDR_CODE_LENGTH]
    if remarks_code != 'REM':
      raise ish_reportException("Parsing remarks. Expected REM but got %s." % (remarks_code,))

    expected_length = int(string[0:4]) + self.PREAMBLE_LENGTH
    position = initial_pos + self.ADDR_CODE_LENGTH
    while position < expected_length:
      key = string[position:position + self.ADDR_CODE_LENGTH]
      if key == 'EQD':
        break
      chars_to_read = string[position + self.ADDR_CODE_LENGTH:position + \
                      (self.ADDR_CODE_LENGTH * 2)]
      chars_to_read = int(chars_to_read)
      position += (self.ADDR_CODE_LENGTH * 2)
      string_value = string[position:position + chars_to_read]
      self._remarks[key] = string_value
      position += chars_to_read
426906
def get_text(self, xml, name):
        
        nodes = xml.getElementsByTagName("wp:comment_" + name)[0].childNodes
        accepted_types = [Node.CDATA_SECTION_NODE, Node.TEXT_NODE]
        return "".join([n.data for n in nodes if n.nodeType in accepted_types])
996872
public static Comments.Comment getCommentAround(R run,
			WordprocessingMLPackage document) {
		try {
			if (run instanceof Child) {
				Child child = (Child) run;
				ContentAccessor parent = (ContentAccessor) child.getParent();
				if (parent == null)
					return null;
				CommentRangeStart possibleComment = null;
				boolean foundChild = false;
				for (Object contentElement : parent.getContent()) {

					// so first we look for the start of the comment
					if (XmlUtils.unwrap(contentElement) instanceof CommentRangeStart) {
						possibleComment = (CommentRangeStart) contentElement;
					}
					// then we check if the child we are looking for is ours
					else if (possibleComment != null && child.equals(contentElement)) {
						foundChild = true;
					}
					// and then if we have an end of a comment we are good!
					else if (possibleComment != null && foundChild && XmlUtils
							.unwrap(contentElement) instanceof CommentRangeEnd) {
						try {
							BigInteger id = possibleComment.getId();
							CommentsPart commentsPart = (CommentsPart) document.getParts()
									.get(new PartName("/word/comments.xml"));
							Comments comments = commentsPart.getContents();
							for (Comments.Comment comment : comments.getComment()) {
								if (comment.getId().equals(id)) {
									return comment;
								}
							}
						}
						catch (InvalidFormatException e) {
							logger.warn(String.format(
									"Error while searching comment. Skipping run %s.",
									run), e);
						}
					}
					// else restart
					else {
						possibleComment = null;
						foundChild = false;
					}
				}
			}
			return null;
		}
		catch (Docx4JException e) {
			throw new DocxStamperException(
					"error accessing the comments of the document!", e);
		}
	}
221611
def process_composite_comment(self, level, comments, key):
        
        if key not in comments:
            comment = ""
        else:
            value = comments[key]
            spacer = self.whitespace(level, 0)

            if isinstance(value, list):
                comments = [self.format_comment(spacer, v) for v in value]
                comment = self.newlinechar.join(comments)
            else:
                comment = self.format_comment(spacer, value)

        return comment
370307
def __extract_tags(self):
        
        tags = list()
        current = None
        for line in self._comment:
            parts = re.match(r'^@(\w+)', line)
            if parts:
                current = (parts.group(1), list())
                tags.append(current)

            if current:
                if line == '':
                    current = None
                else:
                    current[1].append(line)

        for tag in tags:
            self._tags.append((tag[0], os.linesep.join(tag[1])))
976915
function parseComment (comment) {
  const body = j('[' + comment + ']').nodes()[0].program.body
  const array = body[0].expression
  return array.elements
}
817503
function captureTomDoc(comments) {
  // collect lines up to first paragraph break
  const lines = []
  for (let i = 0; i < comments.length; i++) {
    const comment = comments[i]
    if (comment.value.match(/^\s*$/)) break
    lines.push(comment.value.trim())
  }

  // return doctrine-like object
  const statusMatch = lines.join(' ').match(/^(Public|Internal|Deprecated):\s*(.+)/)
  if (statusMatch) {
    return {
      description: statusMatch[2],
      tags: [{
        title: statusMatch[1].toLowerCase(),
        description: statusMatch[2],
      }],
    }
  }
}
885154
def parse_comment(comment):
    
    names, vals = [], []
    pieces = comment.split('=')
    for i, piece in enumerate(pieces):
        if i == 0:  # first line
            names.append(piece.strip())
        elif i == len(pieces) - 1:  # last line
            vals.append(ast.literal_eval(piece))
        else:
            val, name = piece.rsplit(',', 1)
            vals.append(ast.literal_eval(val))
            names.append(name.strip())
    return list(zip(names, vals))
460764
def analyze_reply_code(self, xml_response_dict):
        
        if 'RETS-STATUS' in xml_response_dict:
            attributes = self.get_attributes(xml_response_dict['RETS-STATUS'])
            reply_code = attributes['ReplyCode']
            reply_text = attributes.get('ReplyText', 'RETS did not supply a Reply Text.')

            logger.debug("Received ReplyCode of {0!s} from the RETS Server: {0!s}".format(reply_code, reply_text))
            if reply_code != '0':
                raise RETSException(reply_text, reply_code)

        elif 'RETS' not in xml_response_dict:  # pragma: no cover
            raise RETSException("The <RETS> tag was expected in the response XML but it was not found.")

        attributes = self.get_attributes(input_dict=xml_response_dict['RETS'])
        if 'ReplyCode' not in attributes:  # pragma: no cover
            # The RETS server did not return a response code.
            return True

        reply_code = attributes['ReplyCode']
        reply_text = attributes.get('ReplyText', 'RETS did not supply a Reply Text.')

        logger.debug("Received ReplyCode of {0!s} from the RETS Server: {0!s}".format(reply_code, reply_text))
        if reply_code != '0':
            raise RETSException(reply_text, reply_code)
456010
def get_segment_definer_comments(xml_file, include_version=True):
    """"""

    from glue.ligolw.ligolw import LIGOLWContentHandler as h
    lsctables.use_in(h)

    # read segment definer table
    xmldoc, _ = ligolw_utils.load_fileobj(xml_file,
                                        gz=xml_file.name.endswith(".gz"),
                                        contenthandler=h)
    seg_def_table = table.get_table(xmldoc,
                                    lsctables.SegmentDefTable.tableName)

    # put comment column into a dict
    comment_dict = {}
    for seg_def in seg_def_table:
        if include_version:
            full_channel_name = ':'.join([str(seg_def.ifos),
                                          str(seg_def.name),
                                          str(seg_def.version)])
        else:
            full_channel_name = ':'.join([str(seg_def.ifos),
                                          str(seg_def.name)])

        comment_dict[full_channel_name] = seg_def.comment

    return comment_dict
286794
def parse_comment
      s0 = @current_pos
      if match_str("*") != :failed
        s2 = parse_nonls
        if parse_nl != :failed
          @reported_pos = s0
          s0 = s2.join
        else
          @current_pos = s0
          s0 = :failed
        end
      else
        @current_pos = s0
        s0 = :failed
      end
      if s0 == :failed
        s0 = @current_pos
        s1 = match_str("&")
        if s1 != :failed
          s2 = parse_nonls
          if parse_nl != :failed
            @reported_pos = s0
            s0 = "&" + s2.join
          else
            @current_pos = s0
            s0 = :failed
          end
        else
          @current_pos = s0
          s0 = :failed
        end
      end
      s0
    end
765433
def serialize_comment(ctx, document, el, root):
    ""

    # Check if option is turned on

    if el.comment_type == 'end':
        ctx.opened_comments.remove(el.cid)
    else:
        if el.comment_type != 'reference':
            ctx.opened_comments.append(el.cid)

        if ctx.options['comment_span']:
            link = etree.SubElement(root, 'a')
            link.set('href', '#')
            link.set('class', 'comment-link')    
            link.set('id', 'comment-id-' + el.cid)    

            link.text = ''

            fire_hooks(ctx, document, el, link, ctx.get_hook('comment'))

    return root
115322
def get_tags(doc):
    '''
    
    '''
    tags = list()

    for el in doc.getroot().iter():
        if isinstance(el, lxml.html.HtmlElement):
            tags.append(el.tag)
        elif isinstance(el, lxml.html.HtmlComment):
            tags.append('comment')
        else:
            raise ValueError('Don\'t know what to do with element: {}'.format(el))

    return tags
1295104
def comment(value, comment_text):
    
    if isinstance(value, Doc):
        return comment_doc(value, comment_text)
    return comment_value(value, comment_text)