<?php

/*
 * Copyright 2012 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @group markup
 */
final class PhutilRemarkupRuleMonospace
  extends PhutilRemarkupRule {

  public function apply($text) {
    return preg_replace(
      '@##(.+?)##@s',
      '<tt>\1</tt>',
      $text);
  }

}

<?php

/*
 * Copyright 2012 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @group markup
 */
final class PhutilRemarkupRuleMonospace
  extends PhutilRemarkupRule {

  public function apply($text) {
    return preg_replace(
      array('@##(.+?)##@s', '@\B`(.+?)`\B@'),
      '<tt>\1</tt>',
      $text);
  }

}

Support ` for delimiting monospaced text in Remarkup
Support ` for delimiting monospaced text in Remarkup

Summary:
Command line commands are often denoted by ` in plain text. It is natural to convert them to monospaced text in formatted text.
Other tools (such as GitHub flavored Markdown) use the same delimiter.
Delimiter ## is problematic in commit messages because git eats all lines starting by #. So it is not possible to start a line with monospaced text.

I am not aware about any conflits, old syntax is still supported.

Test Plan:
  `test`
  `test`s
  `test
  test`

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, epriestley

Differential Revision: https://secure.phabricator.com/D1773
