Suivi — Syntaxe markdown bug du sommaire automatique sur les citations

#870 Posté par  (site web personnel) . État de l’entrée : corrigée. Assigné à Bruno Michel.
Étiquettes : aucune
26
17
mar.
2012

Le sommaire généré prend en compte les citations et le « code » ('fin les sections ``` ainsi que celles commençant par >) alors que cela ne devrait pas apparaître.

un exemple sur aide édition

un effet de bord : les titres en dessous sont décalés d'un niveau (H3 au lieu de H2) lorsqu'un titre apparaît dans une citation, j'ai dû éditer aide-edition pour corriger cela :/

  • # et dans les commentaires

    Posté par  (site web personnel) . Évalué à 3 (+0/-0).

    • [^] # Re: et dans les commentaires

      Posté par  (site web personnel) . Évalué à 3 (+0/-0).

      Sommaire

      Je suis aussi sur un fixe et sans onduleur, du coup, j'ai viré tout ce qui touchait à la batterie.

      #!/bin/bash
      
      # An intelligent an non intrusive prompt for bash
      
      # Licensed under the AGPL version 3
      #
      # This program is free software: you can redistribute it and/or modify
      # it under the terms of the GNU Affero General Public License as
      # published by the Free Software Foundation, either version 3 of the
      # License, or (at your option) any later version.
      #
      # This program is distributed in the hope that it will be useful,
      # but WITHOUT ANY WARRANTY; without even the implied warranty of
      # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      # GNU Affero General Public License for more details.
      #
      # You should have received a copy of the GNU Affero General Public License
      # along with this program. If not, see <http://www.gnu.org/licenses/>.
      
      # 2012 (c) nojhan <nojhan@gmail.com>
      
      
      # Below are function for having a flexible dynamic prompt for power user:
      # - display the colored hostname when connected via ssh
      # - when root, color in yellow the [username path] and in red the sharp
      # - when user, print the colored git branch name (if in a git repository):
      # red = some changes are not commited, yellow = some commits are not pushed,
      # green = no changes or commits
      # - if necessary, print a counter for jobs that are attached to the current term (e.g. xterm &)
      # or that are sleeping (e.g. Ctrl-z)
      # - display the load average, colored with a colormap
      # - display the battery level (if necessary), with colormap
      
      # Some colors
      BLUE="\[\033[0;34m\]"
      LIGHT_GRAY="\[\033[0;37m\]"
      LIGHT_GREEN="\[\033[1;32m\]"
      LIGHT_BLUE="\[\033[1;34m\]"
      LIGHT_CYAN="\[\033[1;36m\]"
      YELLOW="\[\033[1;33m\]"
      WHITE="\[\033[1;37m\]"
      RED="\[\033[0;31m\]"
      NO_COL="\[\033[00m\]"
      
      
      #################
      # Where are we? #
      #################
      
      THIS_TTY=tty`ps aux | grep $$ | grep bash | awk '{ print $7 }'`
      SESS_SRC=`who | grep $THIS_TTY | awk '{ print $6 }'`
      
      # Are we in an SSH connexion?
      SSH_FLAG=0
      SSH_IP=`echo $SSH_CLIENT | awk '{ print $1 }'`
      if [ $SSH_IP ] ; then
      SSH_FLAG=1
      fi
      SSH2_IP=`echo $SSH2_CLIENT | awk '{ print $1 }'`
      if [ $SSH2_IP ] ; then
      SSH_FLAG=1
      fi
      if [ $SSH_FLAG -eq 1 ] ; then
      CONN=ssh
      elif [ -z $SESS_SRC ] ; then
      CONN=lcl
      elif [ $SESS_SRC = "(:0.0)" -o $SESS_SRC = "" ] ; then
      CONN=lcl
      else
      CONN=tel
      fi
      
      
      ###############
      # Who are we? #
      ###############
      
      if [ `/usr/bin/whoami` = "root" ] ; then
      USR=u_root
      else
      USR=nou_root
      fi
      
      
      #####################################
      # Count the number of attached jobs #
      #####################################
      
      # Either attached running jobs (started with $ myjob &)
      # or attached stopped jobs (suspended with Ctrl-Z)
      jobcount()
      {
          rep=""
          running=`jobs -r | wc -l | tr -d " "`
          stopped=`jobs -s | wc -l | tr -d " "`
      
          if [ $running != "0" -a $stopped != "0" ] ; then
      rep=" ${running}r/${stopped}s"
      
          elif [ $running != "0" -a $stopped == "0" ] ; then
      rep=" ${running}r"
      
          elif [ $running == "0" -a $stopped != "0" ] ; then
      rep=" ${stopped}s"
          fi
      
      echo -ne "$rep"
      }
      
      ######################
      # GIT branch display #
      ######################
      
      # Get the branch name of the current directory
      git_branch()
      {
          if git rev-parse --git-dir >/dev/null 2>&1 ; then
      gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
          else
      return 0
          fi
      echo -e "$gitver"
      }
      
      # Set a color depending on the branch state:
      # - green if the repository is up to date
      # - yellow if there is some commits not pushed
      # - red if there is changes to commit
      git_branch_color()
      {
          if git rev-parse --git-dir >/dev/null 2>&1 ; then
      red=`tput setaf 1`
              green=`tput setaf 2`
              yellow=`tput setaf 3`
      
              color=""
              if git diff --quiet 2>/dev/null >&2 ; then
      branch="$(git_branch)"
                  has_commit=`git rev-list origin/$branch..$branch`
                  if [ "$has_commit" != "" ] ; then
      color="${yellow}" # some commits to push
                  else
      color="${green}" # nothing to commit or push
                  fi
      else
      color="${red}" # changes to commit
              fi
      else
      return 0
          fi
      echo -ne $color
      }
      
      
      ###############
      # System load #
      ###############
      
      # Get the load average
      load_out()
      {
          load=`uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\).*/\1/" -e "s/ //g"`
          tmp=$(echo $load*100 | bc)
          load100=${tmp%.*}
          if [ ${load100} -gt 50 ] ; then
      echo -n $load
          else
      echo -n ""
          fi
      }
      
      
      ########################
      # Construct the prompt #
      ########################
      
      # different colors depending on connexion type and user
      if [ $CONN = lcl -a $USR = nou_root ] ; then
      PS1="${WHITE}[\u \w]${NO_COL}"
      elif [ $CONN = lcl -a $USR = u_root ] ; then
      PS1="${YELLOW}[\w]${NO_COL}" # no user name if we are local root
      elif [ $CONN = tel -a $USR = nou_root ] ; then
      PS1="[\u${LIGHT_GREEN}@\h${NO_COL} \w]${NO_COL}"
      elif [ $CONN = tel -a $USR = u_root ] ; then
      PS1="${RED}[\u @${YELLOW}\h${RED} \w]${NO_COL}"
      elif [ $CONN = ssh -a $USR = nou_root ] ; then
      PS1="[\u @${LIGHT_BLUE}\h${NO_COL} \w]${NO_COL}"
      elif [ $CONN = ssh -a $USR = u_root ] ; then
      PS1="${RED}[\u @${LIGHT_BLUE}\h${RED} \w]${NO_COL}"
      fi
      
      # add job count
      PS1="$PS1${LIGHT_BLUE}\$(jobcount)${NO_COL}"
      
      if [ $USR = nou_root ] ; then
          # add git branch and status
          PS1="$PS1 \$(git_branch_color)\$(git_branch)${NO_COL}"
      fi
      
      # add prompt mark
      if [ $USR = nou_root ] ; then
      PS1="$PS1${WHITE}\\$ ${NO_COL}"
      elif [ $USR = u_root ] ; then
      PS1="$PS1${RED}\\$ ${NO_COL}"
      fi
      
      # add colored load average
      PS1="\[\$(load_color)\]\$(load_out)${NO_COL}$PS1"
      
      # Glue the bash prompt always go to the first column .
      # Avoid glitches after interrupting a command with Ctrl-C
      PS1="\[\033[G\]$PS1"
      
      
      • [^] # Test de la correction

        Posté par  . Évalué à 3 (+0/-0).

        Je suis aussi sur un fixe et sans onduleur, du coup, j'ai viré tout ce qui touchait à la batterie.

        #!/bin/bash
        
        # An intelligent an non intrusive prompt for bash
        
        # Licensed under the AGPL version 3
        #
        # This program is free software: you can redistribute it and/or modify
        # it under the terms of the GNU Affero General Public License as
        # published by the Free Software Foundation, either version 3 of the
        # License, or (at your option) any later version.
        #
        # This program is distributed in the hope that it will be useful,
        # but WITHOUT ANY WARRANTY; without even the implied warranty of
        # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
        # GNU Affero General Public License for more details.
        #
        # You should have received a copy of the GNU Affero General Public License
        # along with this program. If not, see <http://www.gnu.org/licenses/>.
        
        # 2012 (c) nojhan <nojhan@gmail.com>
        
        
        # Below are function for having a flexible dynamic prompt for power user:
        # - display the colored hostname when connected via ssh
        # - when root, color in yellow the [username path] and in red the sharp
        # - when user, print the colored git branch name (if in a git repository):
        # red = some changes are not commited, yellow = some commits are not pushed,
        # green = no changes or commits
        # - if necessary, print a counter for jobs that are attached to the current term (e.g. xterm &)
        # or that are sleeping (e.g. Ctrl-z)
        # - display the load average, colored with a colormap
        # - display the battery level (if necessary), with colormap
        
        # Some colors
        BLUE="\[\033[0;34m\]"
        LIGHT_GRAY="\[\033[0;37m\]"
        LIGHT_GREEN="\[\033[1;32m\]"
        LIGHT_BLUE="\[\033[1;34m\]"
        LIGHT_CYAN="\[\033[1;36m\]"
        YELLOW="\[\033[1;33m\]"
        WHITE="\[\033[1;37m\]"
        RED="\[\033[0;31m\]"
        NO_COL="\[\033[00m\]"
        
        
        #################
        # Where are we? #
        #################
        
        THIS_TTY=tty`ps aux | grep $$ | grep bash | awk '{ print $7 }'`
        SESS_SRC=`who | grep $THIS_TTY | awk '{ print $6 }'`
        
        # Are we in an SSH connexion?
        SSH_FLAG=0
        SSH_IP=`echo $SSH_CLIENT | awk '{ print $1 }'`
        if [ $SSH_IP ] ; then
        SSH_FLAG=1
        fi
        SSH2_IP=`echo $SSH2_CLIENT | awk '{ print $1 }'`
        if [ $SSH2_IP ] ; then
        SSH_FLAG=1
        fi
        if [ $SSH_FLAG -eq 1 ] ; then
        CONN=ssh
        elif [ -z $SESS_SRC ] ; then
        CONN=lcl
        elif [ $SESS_SRC = "(:0.0)" -o $SESS_SRC = "" ] ; then
        CONN=lcl
        else
        CONN=tel
        fi
        
        
        ###############
        # Who are we? #
        ###############
        
        if [ `/usr/bin/whoami` = "root" ] ; then
        USR=u_root
        else
        USR=nou_root
        fi
        
        
        #####################################
        # Count the number of attached jobs #
        #####################################
        
        # Either attached running jobs (started with $ myjob &)
        # or attached stopped jobs (suspended with Ctrl-Z)
        jobcount()
        {
            rep=""
            running=`jobs -r | wc -l | tr -d " "`
            stopped=`jobs -s | wc -l | tr -d " "`
        
            if [ $running != "0" -a $stopped != "0" ] ; then
        rep=" ${running}r/${stopped}s"
        
            elif [ $running != "0" -a $stopped == "0" ] ; then
        rep=" ${running}r"
        
            elif [ $running == "0" -a $stopped != "0" ] ; then
        rep=" ${stopped}s"
            fi
        
        echo -ne "$rep"
        }
        
        ######################
        # GIT branch display #
        ######################
        
        # Get the branch name of the current directory
        git_branch()
        {
            if git rev-parse --git-dir >/dev/null 2>&1 ; then
        gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
            else
        return 0
            fi
        echo -e "$gitver"
        }
        
        # Set a color depending on the branch state:
        # - green if the repository is up to date
        # - yellow if there is some commits not pushed
        # - red if there is changes to commit
        git_branch_color()
        {
            if git rev-parse --git-dir >/dev/null 2>&1 ; then
        red=`tput setaf 1`
                green=`tput setaf 2`
                yellow=`tput setaf 3`
        
                color=""
                if git diff --quiet 2>/dev/null >&2 ; then
        branch="$(git_branch)"
                    has_commit=`git rev-list origin/$branch..$branch`
                    if [ "$has_commit" != "" ] ; then
        color="${yellow}" # some commits to push
                    else
        color="${green}" # nothing to commit or push
                    fi
        else
        color="${red}" # changes to commit
                fi
        else
        return 0
            fi
        echo -ne $color
        }
        
        
        ###############
        # System load #
        ###############
        
        # Get the load average
        load_out()
        {
            load=`uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\).*/\1/" -e "s/ //g"`
            tmp=$(echo $load*100 | bc)
            load100=${tmp%.*}
            if [ ${load100} -gt 50 ] ; then
        echo -n $load
            else
        echo -n ""
            fi
        }
        
        
        ########################
        # Construct the prompt #
        ########################
        
        # different colors depending on connexion type and user
        if [ $CONN = lcl -a $USR = nou_root ] ; then
        PS1="${WHITE}[\u \w]${NO_COL}"
        elif [ $CONN = lcl -a $USR = u_root ] ; then
        PS1="${YELLOW}[\w]${NO_COL}" # no user name if we are local root
        elif [ $CONN = tel -a $USR = nou_root ] ; then
        PS1="[\u${LIGHT_GREEN}@\h${NO_COL} \w]${NO_COL}"
        elif [ $CONN = tel -a $USR = u_root ] ; then
        PS1="${RED}[\u @${YELLOW}\h${RED} \w]${NO_COL}"
        elif [ $CONN = ssh -a $USR = nou_root ] ; then
        PS1="[\u @${LIGHT_BLUE}\h${NO_COL} \w]${NO_COL}"
        elif [ $CONN = ssh -a $USR = u_root ] ; then
        PS1="${RED}[\u @${LIGHT_BLUE}\h${RED} \w]${NO_COL}"
        fi
        
        # add job count
        PS1="$PS1${LIGHT_BLUE}\$(jobcount)${NO_COL}"
        
        if [ $USR = nou_root ] ; then
            # add git branch and status
            PS1="$PS1 \$(git_branch_color)\$(git_branch)${NO_COL}"
        fi
        
        # add prompt mark
        if [ $USR = nou_root ] ; then
        PS1="$PS1${WHITE}\\$ ${NO_COL}"
        elif [ $USR = u_root ] ; then
        PS1="$PS1${RED}\\$ ${NO_COL}"
        fi
        
        # add colored load average
        PS1="\[\$(load_color)\]\$(load_out)${NO_COL}$PS1"
        
        # Glue the bash prompt always go to the first column .
        # Avoid glitches after interrupting a command with Ctrl-C
        PS1="\[\033[G\]$PS1"
        
        

        « Rappelez-vous toujours que si la Gestapo avait les moyens de vous faire parler, les politiciens ont, eux, les moyens de vous faire taire. » Coluche

  • # Corrigé

    Posté par  (site web personnel) . Évalué à 4 (+0/-0).

Envoyer un commentaire

Suivre le flux des commentaires

Note : les commentaires appartiennent à celles et ceux qui les ont postés. Nous n’en sommes pas responsables.